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

Lua bundled cables and pistons

Started by _Zoopy_, 02 December 2012 - 09:33 PM
_Zoopy_ #1
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.
Orwell #2
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)
_Zoopy_ #3
Posted 03 December 2012 - 12:05 AM
aaah, thank you very much, spent about 3 hours trying to get this to work.