Jump to content




Lua bundled cables and pistons


  • You cannot reply to this topic
2 replies to this topic

#1 _Zoopy_

  • New Members
  • 2 posts

Posted 02 December 2012 - 10:33 PM

Ok, so ive written a code that (is supposed to) push out a piston on the corresponding floor to what is written , heres the code

term.clear()
write ("")
print ("Please Choose a floor")
print ("Floor Choices")
print ("Reactor")
print ("Computer")
print ("Railcraft")


x = io.read()

if x == ("Reactor") then
rs.setBundledOutput ("back", 0)
rs.setBundledOutput ("back", colors.purple)
print ("Have a nice day.")
sleep(3)


if x == ("Computer") then
rs.setBundledOutput ("back", 0)
rs.setBundledOutput ("back", colors.red)
print ("Have a nice day.")
sleep(3)

if x == ("Railcraft") then
rs.setBundledOutput ("back", 0)
print ("Have a nice day.")
sleep(3)
else

print ("Invalid floor name.")
sleep(3)

end
end
end



When i type "Reactor" it works fine and disables the other redstone outputs and enables purple then says have a nice day, but when i type "Computer" it disables other outputs but doesnt enable red and doesnt say have a nice day. When i type "Railcraft" it diables other outputs and doesnt say have a nice day.

Any help would be greatly appreciated.

#2 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 02 December 2012 - 11:41 PM

Your conditionals are nested. The if x == ("Computer") then will only be reached if it went through x == ("Reactor"). Make it like this:
term.clear()
write ("")
print ("Please Choose a floor")
print ("Floor Choices")
print ("Reactor")
print ("Computer")
print ("Railcraft")

x = io.read()
if x == ("Reactor") then
rs.setBundledOutput ("back", 0)
rs.setBundledOutput ("back", colors.purple)
print ("Have a nice day.")
sleep(3)
elseif x == ("Computer") then
rs.setBundledOutput ("back", 0)
rs.setBundledOutput ("back", colors.red)
print ("Have a nice day.")
sleep(3)
elseif x == ("Railcraft") then
rs.setBundledOutput ("back", 0)
print ("Have a nice day.")
sleep(3)
else
print ("Invalid floor name.")
sleep(3)
end
Edit: also, I don't know if this is necessary, but if you want to make it pulse. You might want to add a short sleep between setting ouput to zero and setting it to a color. Mike this:
rs.setBundledOutput ("back", 0)
sleep(0.1)
rs.setBundledOutput ("back", colors.purple)


#3 _Zoopy_

  • New Members
  • 2 posts

Posted 03 December 2012 - 12:05 AM

aaah, thank you very much, spent about 3 hours trying to get this to work.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users