This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Desslink's profile picture

help for bundled cable

Started by Desslink, 13 January 2013 - 10:38 AM
Desslink #1
Posted 13 January 2013 - 11:38 AM
Hello, everybody!

I want to do something with bundled cable.
I want to do like a flip-flop for activate/desactivate my lamps, with one program in the yellow cable I do like this:


if redstone.getBundledOutput("back", colors.yellow) == false then
redstone.setBundledOutput("back", colors.yellow, true)
else
redstone.setBundledOutput("back", colors.yellow, false)
end

and when I launch the program it returns me :

lamp:1: attempt to index ? (a nil value)

so I don't know what it is
if you know how to do or how to fix it.

Thanks

PS: I'm frensh so sorry for my bad english :@
remiX #2
Posted 13 January 2013 - 11:49 AM
Instead of
if redstone.getBundledOutput("back", colors.yellow) == false then
try using
if redstone.testBundledInput("back", colours.yellow) then

When in doubt, check the wiki :)/>
Desslink #3
Posted 13 January 2013 - 08:54 PM
Ok, first of all, thank you. I've do this and I add something like this:

if redstone.testBundledInput("back", colors.yellow) then
if input == "false" then
redstone.setBundledOutput("back", colors.yellow, true)
else
redstone.setBundledOutput("back", colors.yellow, false)
end
end

and it returns me :

lamp:5: Expected string, number
columna1 #4
Posted 13 January 2013 - 09:06 PM
the way you use "redstone.setBundledOutput()" is like this
redstone.setBundledOutput(side,color)
there is no boolean as an argument (true or false)
so all of them should look like: redstone.setBundledOutput("back",colors.yellow)
to turn one off you do redstone.setBundledOutput("back",0)
theoriginalbit #5
Posted 13 January 2013 - 09:09 PM
you could do this if you KNOW that yellow is on by doing


rs.setBundledOutput( "back", rs.getBundledOutput( "back" ) - colors.yellow )
Desslink #6
Posted 13 January 2013 - 09:13 PM
Ok but this

redstone.setBundledOutput("back",0)
will not reset all of the colors ?

and i don't know what do you mean TheOriginalBIT
theoriginalbit #7
Posted 13 January 2013 - 09:24 PM
redstone.setBundledOutput( "back", 0 ) will turn them all off…

what I meant is this:


local input = read()

if input == "turn off yellow" and rs.testBundledInput( "back", colors.yellow ) then
  rs.setBundledOutput( "back", rs.getBundledInput( "back" ) - colors.yellow )
else
  print( "Yellow isn't on")
end

That will turn off yellow if it is on, but leave all the others on…
Edited on 13 January 2013 - 08:27 PM
Desslink #8
Posted 13 January 2013 - 09:27 PM
Ok and there is a way to turn them off individually ?
theoriginalbit #9
Posted 13 January 2013 - 09:28 PM
read edit
Desslink #10
Posted 13 January 2013 - 09:39 PM
Ok, but this don't turn on if it's off and vice-versa ?
theoriginalbit #11
Posted 13 January 2013 - 10:05 PM
try this out:

local input = read()

if input == "toggle yellow" then
  local num = ( rs.testBundledInput( "back", colors.yellow ) and -colors.yellow or colors.yellow )
  rs.setBundledOutput( "back", rs.getBundledInput( "back" ) + num  )
  print( "Yellow is now "..( rs.testBundledInput( "back", colors.yellow ) and "on" or "off" )
end
this should set the output based on the if yellow is on or off…
Edited on 13 January 2013 - 09:09 PM
Desslink #12
Posted 13 January 2013 - 10:59 PM
and now it returns me a:

bios:338: [string "light"]:6: unexpected symbol
and I've the exact same code at line 6
theoriginalbit #13
Posted 13 January 2013 - 11:25 PM
sorry missed a closing ) at the end of line 6
Desslink #14
Posted 13 January 2013 - 11:57 PM
that means I must have:

print( "Yellow is now "..( rs.testBundledInput( "back", colors.yellow ) and "on" or "off" ))
????
theoriginalbit #15
Posted 14 January 2013 - 12:08 AM
yes that should be fine now…
Desslink #16
Posted 14 January 2013 - 12:30 AM
it returns me the exact same error
theoriginalbit #17
Posted 14 January 2013 - 12:42 AM
odd… give me a bit, have to go do some house work then I'll open up Minecraft and test it for you…
theoriginalbit #18
Posted 14 January 2013 - 02:23 AM
ok so I just tested this code and it works perfectly


local function toggleColor( c )
	if redstone.testBundledInput( "back", c ) then
		rs.setBundledOutput( "back", rs.getBundledInput( "back" ) - c  )
	else
		rs.setBundledOutput( "back", rs.getBundledInput( "back" ) + c  )
	end

	print( c.." toggled is now "..( rs.testBundledInput( "back", c ) and "off" or "on" ) )
end

what I used to test it


while true do
	local input = read()

	if input == "off" then
		rs.setBundledOutput( "back", 0 )
	elseif tonumber( input ) > 1 and tonumber( input ) < 16 then
		toggleColor( 2 ^ tonumber( input ) )
	end
end


EDIT: Or here is similar as what I posted in replies above, functionally its no different than above example code, just smaller in size


local function toggleColor( c )
  rs.setBundledOutput( "back", rs.getBundledInput( "back" ) + ( rs.testBundledInput( "back", c ) and -c or c )  )
  print( c.." toggled is now "..( rs.testBundledInput( "back", c ) and "off" or "on" ) )
end
Edited on 14 January 2013 - 01:27 AM
Desslink #19
Posted 14 January 2013 - 04:59 AM
Ok I will test it, thanks