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

2 if input == "...." statements

Started by RealGaming, 18 October 2012 - 09:59 AM
RealGaming #1
Posted 18 October 2012 - 11:59 AM
Hi!

i have a question, i want 2 if statements and then a else statement.
this is the code

————————————————-
if input == ""on"" then
term.clear()
term.setCursorPos(12,4)
print("TURNING ON NUCLEAR REACTOR")
sleep(3)
rs.setOutput("back", true)
shell.run("nuclear") – same program so you can turn it off again
if input == "off" then
term.clear()
term.setCursorPos(12,4)
print("TURNING OFF NUCLEAR REACTOR")
rs.setOutput("back', false)
shell.run("nuclear")
end
else

term.clear()
term.setCursorPos(12,4)
print("COMMAND NOT RECONIZED!")
sleep(3)
shell.run("nuclear")
end
——————————————————–

please help
if i type on, it does work
and when i type off it says the print("COMMAND NOT RECONIZED")
Luanub #2
Posted 18 October 2012 - 12:24 PM
You've got ends in the wrong places and instead of two if's do if then elseif then end. Here is the sytax:

if input == "on" then
--code here
elseif input == "off" then
--code here
else
--code here
end
RealGaming #3
Posted 18 October 2012 - 12:35 PM
MUCH MUCH MUCH THX!
it worked:)