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

Arrangement of ends.

Started by Nikolai, 03 December 2012 - 06:10 PM
Nikolai #1
Posted 03 December 2012 - 07:10 PM
Do I have to put all these ends at the bottom like this? Can I just put them at the end of each if statement?


os.pullEvent = os.pullEventRaw
while true do
term.clear()
term.setCursorPos(1,1)
write("Enter Command:")
UserInput = io.read()
if UserInput == "shutdownall" then
rs.setBundledOutput ("back" , colors.orange )
rs.setBundledOutput ("back" , colors.yellow )
print ("Reactors 1-10 are no longer active")

else if UserInput == "shutdown1-5" then
rs.setBundledOutput ("back" , colors.orange )
print ("Reactors 1-5 are no longer active")

else if UserInput == "shutdown6-10" then
rs.setBundledOutput ("back" , colors.yellow )
print ("Reactors 6-10 are no longer active")

else if UserInput == "draincoolant" then
rs.setBundledOutput ("back" , colors.red )
print ("WARNING: Coolant levels dropping")
rs.setBundledOutput ("back" , colors.black ) --This will be the alarm.
sleep(7)
rs.setBundledOutput ("back" , colors.subtract(rs.getBundledOutput("back"),colors.black))

else if UserInput == "restart1-5" then
rs.setBundledOutput("back" , colors.subtract(rs.getBundledOutput("back"),colors.orange))
print ("Reactors 1-5 are now active")

else if UserInput == "restart6-10" then
rs.setBundledOutput("back" , colors.subtract(rs.getBundledOutput("back"),colors.yellow))
print ("Reactors 6-10 are now active")

else if UserInput == "restartall" then
rs.setBundledOutput("back" , colors.subtract(rs.getBundledOutput("back"),colors.orange))
rs.setBundledOutput("back" , colors.subtract(rs.getBundledOutput("back"),colors.yellow))
print ("Reactors 1-10 are now active")

else if UserInput == "fillcoolant" then
rs.setBundledOutput ("back" , colors.subtract(rs.getBundledOutput("back"),colors.red))
rs.setBundledOutput ("back" , colors.green )
print ("Coolant levels rising")

else if UserInput == "soundalarm" then
rs.setBundledOuput ("back" , color.blue )
print ("Sirens activated")

else if UserInput == "stopalarm" then
rs.setBundledOutput ("back" , colors.subtract(rs.getBundledOutput("back"),colors.blue))
print("Sirens deactivated")

else if UserInput == "openblastdoors" then
rs.setBundledOutput ("back" , colors.lime )
print ("Blast doors opened")

else if UserInput == "closeblastdoors" then
rs.setBundledOutput ("back" , colors.subtract(rs.getBundledOutput("back"),colors.lime))
print ("Blast doors closed")

else if UserInput == "stopreplenish" then --stop depleted uranium replacement
rs.setBundledOutput ("back" , colors.subtract(rs.getBundledOuput("back"),colors.cyan))
print ("Replenishment cycle stopped")

else if UserInput == "startreplenish" then
rs.setBundledOutput ("back" , colors.cyan )
print ("Replenishment cycle resumed")
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
Kingdaro #2
Posted 03 December 2012 - 07:24 PM
You could combine all of the "else if"s into "elseif"s, then remove all ends but one.

The structure of ifs and elseifs goes something like this:

while true do
  if condition then
    -- stuff
  elseif another_condition then
    -- more stuff
  else
    -- even more stuff
  end
end
Nikolai #3
Posted 03 December 2012 - 07:29 PM
ok