zaper270 Posted August 23, 2012 Posted August 23, 2012 I have set up a system that allows me to activate or dis-activate any of my machines in my house on tekkit. The problem is though is that when i activate one it just turns off all the others. Can someone figure out whats wrong and show me what i need to do? while true do term.clear() term.setCursorPos(1,1) write(" Input command here: ") local input = read() if input == "sorter_on" then rs.setBundledOutput("bottom" , colors.white) print("Item sorter turned on") sleep(2) term.clear() term.setCursorPos(1,1) end if input == "sorter_off" then rs.setBundledOutput("bottom" , colors.white) print("Item sorter turned off") sleep(2) term.clear() term.setCursorPos(1,1) end if input == "block_on" then rs.setBundledOutput("bottom" , colors.red) print("Block condenser turned on") sleep(2) term.clear() term.setCursorPos(1,1) end if input == "block_off" then rs.setBundledOutput("bottom" , colors.red) print("Block condenser turned off") sleep(2) term.clear() term.setCursorPos(1,1) end if input == "music_on" then rs.setBundledOutput("bottom", rs.getBundledOutput("bottom") + colors.blue) end if input == "commands" then print("sortert_on") print("sorter_off") print("block_on") print("block_off") print("commands") sleep(4) term.clear() term.setCursorPos(1,1) end end Quote
disconsented Posted August 23, 2012 Posted August 23, 2012 Use Elseif/Elif, Its mainly good programming practice. That is the only issue at the moment that I can make out, generally if I incur a bug like this I usually use print() to allow me to see when and if each line of code or segment is executed. Quote
zaper270 Posted August 23, 2012 Author Posted August 23, 2012 Ill see how that works. Thanks for the reply Edit: gah still turns all the others off and only activates the one i turned on/off last. Probably has to do with the while true do command Quote
SmileyJeff Posted August 23, 2012 Posted August 23, 2012 The problem is with colored cable. Currently computercraft website is down so i don't remember the exact function to call. But you have to do something like this for colored cables: local c = {} c = colors.combine( c, colors.red ) So for your code it should look like this (Once again i am not sure if the syntax or usage is correct as i can't refer to computercraft.info right now (its down) and this is from the top of my head) if input == "sorter_on" then c = colors.combine( c, colors.white ) ... end if input == "sorter_off" then c = colors.subtract( c, colors.white ) end -- end of code rs.setBundledOutput( "bottom", c ) Quote
zaper270 Posted August 23, 2012 Author Posted August 23, 2012 i don't think the function is exactly right but i will probably be along those lines. And yes its a real pain having computercraft.info down Quote
SmileyJeff Posted August 23, 2012 Posted August 23, 2012 Just got home, checked my old program. Here is the correct sample code: local outputSide = "bottom" -- if you set rs.setBundledOutput( side, 0 ), it will close all colors off. -- You can name this anything you want local activeColors = 0 ... if input == "redOn" then activeColors = colors.combine( activeColors, colors.red ) end if input == "redOff" then activeColors = colors.subtract( activeColors, colors.red ) end if input == "blueOn" then activeColors = colors.combine( activeColors, colors.blue ) end if input == "blueOff" then activeColors = colors.subtract( activeColors, colors.blue ) end ... -- end of code rs.setBundledOutput( outputSide, activeColors ) Hope it helped! [: Quote
zaper270 Posted August 23, 2012 Author Posted August 23, 2012 Ah thanks a lot Jeff. I finally got the system working properly :) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.