Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- implicitly localize and initialize variables that outside of functions
- local password, key = "",""
- -- setup your functions that contain code you wish to reuse
- function startReactor(type,unit,bundleColor)
- -- type will be either "breeder" or "quad core"
- -- unit is its unit designation number
- -- bundleColor is the numerical value of the colors needed to activate the redstone to turn on the reactor
- wipeScreen()
- delayPrint(3,"Loading Mainframe...")
- print()
- delayPrint(2,"Loading Subsystems...")
- print()
- if type == "breeder" then
- delayPrint(2,"Starting Breeder Reactor " .. unit .. "...")
- else -- maybe we don't want to chain an if but want instead a failsafe execution if the above test is false
- delayPrint(2,"Starting Reactor Quad Core " .. unit .. "...")
- end
- redstone.setBundledOutput("back", bundleColor)
- sleep(2)
- redstone.setBundledOutput("back", 0)
- print()
- print(" Reactor quad core 1 Successfully Started")
- if type == "breeder" then
- delayPrint(2,"Breeder Reactor " .. unit .. " Successfully Started")
- else
- delayPrint(2,"Reactor Quad Core " .. unit .. " Successfully Started")
- end
- end -- the end of the function
- function wipeScreen()
- term.clear()
- term.setCursorPos(1, 1)
- end
- function delayPrint(pause,msg)
- print(msg)
- sleep(pause)
- end
- function getKey(prompt)
- local key = "" -- not the same as the other key outside the function
- print(prompt)
- _, key = os.pullEvent("char") -- char is an event that occurs when keyboard key is pressed
- return key -- send key back as value to the calling line for assignment or processing
- end
- -- functions shouldn't be defined after this point as what is below is the main body of the program
- wipeScreen()
- print("Uranium Tech.Inc")
- write("Enter password to access controls: ")
- password = read("*")
- if password ~= "DarkDeath" then
- print("Unauthorized Access! Reactor Meltdown Emminent!")
- return -- if you don't type the right password this line shoots back out of the program
- else
- print("Well Done Master! You've remembered your password after a night of binge drinking!")
- -- but you did so it keeps you in the program
- end
- _ = getKey("Press any key to continue.") -- if we don't do this no one will see the success message above.
- -- now let's start that forever loop I told you about
- while true do -- you see true is always true so the loop keeps running
- wipeScreen()
- print("Nuclear Reactor Control Mainframe")
- print()
- print("1. Start Reactor quad core 1 - Press 1")
- print ("2. Start Reactor quad core 2 - Press 2")
- print("3. Start Breeder Reactor 1 - Press 3")
- print("4. Start Breeder Reactor 2 - Press 4")
- print("5. Stop Reactor quad core 1 - Press 5")
- print("6. Stop Reactor quad core 2 - Press 6")
- print("7. Stop Breeder Reactor 1 - Press 7")
- print("8. Stop Breeder Reactor 2 - Press 8")
- print("9. Start and Stop Refueling Process - Press 9")
- print("10. Re-route Power to the Mass. Fab. Array - Press q")
- print("11. Re-route Power to the Main line - Press w")
- print("12. Close/Open Maintenance Blast Doors - Press e")
- print("13. Start/Stop full auto cycles - Press r")
- print("14. Activate Self-destruct sequence - Press t")
- print("15. Cancel and Shutdown - Press y")
- key = getKey("Your command?")
- if key == "1" then
- startReactor("quad",1,colors.red)
- elseif key == "2" then
- startReactor("quad",2,colors.cyan)
- elseif key == "3" then
- startReactor("breeder",3,colors.magenta)
- elseif key == "4" then
- startReactor("breeder",4,colors.green)
- end -- stop testing key for now
- end -- this is the other side of the forever loop when cc sees this it shoots back to the line containing the "while"
- --[[ I see now why the others didn't want to throw you a bone and are leaving the thread alone. They are teaching me a lesson in compassion. I am feeling abused here. ]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement