Jump to content

Recommended Posts

Posted

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

Posted

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.

Posted

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

Posted

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 )

Posted

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! [:

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...