23 posts
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 :@
2088 posts
Location
South Africa
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 :)/>
23 posts
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
57 posts
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)
7508 posts
Location
Australia
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 )
23 posts
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
7508 posts
Location
Australia
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
23 posts
Posted 13 January 2013 - 09:27 PM
Ok and there is a way to turn them off individually ?
7508 posts
Location
Australia
Posted 13 January 2013 - 09:28 PM
read edit
23 posts
Posted 13 January 2013 - 09:39 PM
Ok, but this don't turn on if it's off and vice-versa ?
7508 posts
Location
Australia
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
23 posts
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
7508 posts
Location
Australia
Posted 13 January 2013 - 11:25 PM
sorry missed a closing ) at the end of line 6
23 posts
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" ))
????
7508 posts
Location
Australia
Posted 14 January 2013 - 12:08 AM
yes that should be fine now…
23 posts
Posted 14 January 2013 - 12:30 AM
it returns me the exact same error
7508 posts
Location
Australia
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…
7508 posts
Location
Australia
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
23 posts
Posted 14 January 2013 - 04:59 AM
Ok I will test it, thanks