Posted 19 August 2012 - 04:18 PM
I'm writing a program to control the systems in my warehouse. I guess my code is sloppy, is there any way that I can make it more organized ? like using functions and such ? help or examples would be great!
force = "1"
power = "2"
gate = "3"
four = "4"
five = "5"
resource = "4"
while true do
term.clear()
term.setCursorPos(1,1)
print("--------------------------------------------------")
print("WAREHOUSE CONTROL SYSTEM")
print("--------------------------------------------------")
print("Choose an option")
print("")
print("[1] Force Shield")
print("[2] Power")
print("[3] Gate Systems")
print("[4] Resource Management")
print("")
print("--------------------------------------------------")
print("--------------------------------------------------")
term.setCursorPos(1,13)
input = read()
if input == force then
term.clear()
term.setCursorPos(1,1)
print("--------------------------------------------------")
print("FORCEFIELD SYSTEM")
print("--------------------------------------------------")
print("")
print("[1] Turn On EU Injection")
print("[2] Turn OFF EU injection")
print("[3] Turn On FORCESHIELD")
print("[4] Turn OFF FORCESHIELD")
print("[5] Main Menu")
print("")
print("--------------------------------------------------")
print("--------------------------------------------------")
term.setCursorPos(1,13)
input = read()
if input == force then
---- code here
elseif input == power then
----- code here
elseif input == gate then
----- code here
elseif input == four then
----- code here
elseif input == five then
----- code here
end
elseif input == power then
term.clear()
term.setCursorPos(1,1)
print("--------------------------------------------------")
print("POWER CONTROL SYSTEM")
print("--------------------------------------------------")
print("Choose an option")
print("")
print("[1] Turn On Reactor")
print("[2] Turn Off Reactor")
print("[3] Block Energy Transfer")
print("[4] Unblock Energy Transfer")
print("[5] Exit")
print("")
print("--------------------------------------------------")
print("--------------------------------------------------")
term.setCursorPos(1,14)
input = read()
if input == force then
---- code here
elseif input == power then
----- code here
elseif input == gate then
----- code here
elseif input == four then
----- code here
elseif input == five then
----- code here
end
elseif input == gate then
term.clear()
term.setCursorPos(1,1)
print("--------------------------------------------------")
print("GATE CONTROL SYSTEM")
print("--------------------------------------------------")
print("Choose an option")
print("")
print("[1] Open all gates")
print("[2] Close all gates")
print("[3] Seal all gates")
print("[4] Unseal all gates")
print("[5] Exit")
print("")
print("--------------------------------------------------")
print("--------------------------------------------------")
term.setCursorPos(1,14)
input = read()
if input == force then
---- code here
elseif input == power then
----- code here
elseif input == gate then
----- code here
elseif input == four then
----- code here
elseif input == five then
----- code here
end
elseif input == four then
term.clear()
term.setCursorPos(1,1)
print("--------------------------------------------------")
print("RESOURCE CONTROL SYSTEM")
print("--------------------------------------------------")
print("Choose an option")
print("")
print("[1] Turn On sorting Machine")
print("[2] Turn Off Sorting Machine")
print("[5] Exit")
print("")
print("--------------------------------------------------")
print("--------------------------------------------------")
term.setCursorPos(1,12)
input = read()
if input == force then
---- code here
elseif input == power then
----- code here
elseif input == five then
----- code here
end
end
end