Advertisement
kreezxil

reactor control - a new beginning

Sep 15th, 2013
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.97 KB | None | 0 0
  1. -- implicitly localize and initialize variables that outside of functions
  2. local password, key = "",""
  3.  
  4. -- setup your functions that contain code you wish to reuse
  5. function startReactor(type,unit,bundleColor)
  6.   -- type will be either "breeder" or "quad core"
  7.   -- unit is its unit designation number
  8.   -- bundleColor is the numerical value of the colors needed to activate the redstone to turn on the reactor
  9.      wipeScreen()
  10.      delayPrint(3,"Loading Mainframe...")
  11.      print()
  12.      delayPrint(2,"Loading Subsystems...")
  13.      print()
  14.      if type == "breeder" then
  15.         delayPrint(2,"Starting Breeder Reactor " .. unit .. "...")
  16.      else -- maybe we don't want to chain an if but want instead a failsafe execution if the above test is false
  17.         delayPrint(2,"Starting Reactor Quad Core " .. unit .. "...")
  18.      end
  19.      redstone.setBundledOutput("back", bundleColor)
  20.      sleep(2)
  21.      redstone.setBundledOutput("back", 0)
  22.      print()
  23.      print(" Reactor quad core 1 Successfully Started")
  24.      if type == "breeder" then
  25.         delayPrint(2,"Breeder Reactor " .. unit .. " Successfully Started")
  26.      else
  27.         delayPrint(2,"Reactor Quad Core " .. unit .. " Successfully Started")
  28.      end
  29. end -- the end of the function
  30.  
  31. function wipeScreen()
  32.    term.clear()
  33.    term.setCursorPos(1, 1)
  34. end
  35.  
  36. function delayPrint(pause,msg)
  37.    print(msg)
  38.    sleep(pause)
  39. end
  40.  
  41. function getKey(prompt)
  42.   local key = "" -- not the same as the other key outside the function
  43.   print(prompt)
  44.   _, key = os.pullEvent("char") -- char is an event that occurs when keyboard key is pressed
  45.   return key -- send key back as value to the calling line for assignment or processing
  46. end
  47.  
  48. -- functions shouldn't be defined after this point as what is below is the main body of the program
  49.  
  50. wipeScreen()
  51. print("Uranium Tech.Inc")
  52. write("Enter password to access controls: ")
  53. password = read("*")
  54.  
  55. if password ~= "DarkDeath" then
  56.    print("Unauthorized Access! Reactor Meltdown Emminent!")
  57.    return -- if you don't type the right password this line shoots back out of the program
  58. else
  59.    print("Well Done Master! You've remembered your password after a night of binge drinking!")
  60.    -- but you did so it keeps you in the program
  61. end
  62.  
  63. _ = getKey("Press any key to continue.") -- if we don't do this no one will see the success message above.
  64.  
  65.  
  66. -- now let's start that forever loop I told you about
  67.  
  68. while true do -- you see true is always true so the loop keeps running
  69.    
  70.    wipeScreen()
  71.  
  72.    print("Nuclear Reactor Control Mainframe")
  73.    print()
  74.    print("1. Start Reactor quad core 1 - Press 1")
  75.    print ("2. Start Reactor quad core 2 - Press 2")
  76.    print("3. Start Breeder Reactor 1 - Press 3")
  77.    print("4. Start Breeder Reactor 2 - Press 4")
  78.    print("5. Stop Reactor quad core 1 - Press 5")
  79.    print("6. Stop Reactor quad core 2 - Press 6")
  80.    print("7. Stop Breeder Reactor 1 - Press 7")
  81.    print("8. Stop Breeder Reactor 2 - Press 8")
  82.    print("9. Start and Stop Refueling Process - Press 9")
  83.    print("10. Re-route Power to the Mass. Fab. Array - Press q")
  84.    print("11. Re-route Power to the Main line - Press w")
  85.    print("12. Close/Open Maintenance Blast Doors - Press e")
  86.    print("13. Start/Stop full auto cycles - Press r")
  87.    print("14. Activate Self-destruct sequence - Press t")
  88.    print("15. Cancel and Shutdown - Press y")
  89.  
  90.    key = getKey("Your command?")
  91.    if key == "1" then
  92.       startReactor("quad",1,colors.red)
  93.    elseif key == "2" then
  94.       startReactor("quad",2,colors.cyan)  
  95.    elseif key == "3" then
  96.       startReactor("breeder",3,colors.magenta)
  97.    elseif key == "4" then
  98.       startReactor("breeder",4,colors.green)
  99.    end -- stop testing key for now
  100.  
  101. end -- this is the other side of the forever loop when cc sees this it shoots back to the line containing the "while"
  102.  
  103. --[[ 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