OreSeur-

My Reactor Code 2

Jan 16th, 2021 (edited)
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.75 KB | None | 0 0
  1. --This code is designed to leave the reactor on all the times and maintain
  2. --power levels by adjusting the control rod insertion
  3.  
  4. --return a integar ignoring any remainder
  5. function DIV(a,b)
  6.     return (a - (a % b)) / b
  7. end
  8.  
  9. --the total size of the buffer
  10. local BUFFER_MAX = 10000000
  11. --the amount of power we want to maintain in the buffer
  12. local TARGET_AMOUNT = 5000000
  13. --the default insertion of control rods
  14. local controlLevel = 50
  15.  
  16. --connect to reactor
  17. local reactor = peripheral.wrap("back")
  18.  
  19. --confirm connection
  20. if(not reactor.getConnected) then
  21.     print("Not connected to Reactor")
  22. end
  23.  
  24. --turn the reactor on
  25. if(not reactor.getActive()) then
  26.     reactor.setActive(true)
  27.     print("Starting Reactor")
  28. end
  29.  
  30. --move control rod to defaul level
  31. reactor.setAllControlRodLevels(controlLevel)
  32.  
  33. while(true) do
  34.     --control the rods to maintain a specified buffer
  35.    
  36.     --find the current amount of energy in the buffer
  37.     local currentEnergy = reactor.getEnergyStored()
  38.     --set the new control level to the difference between the
  39.     --amount of evergy and wanted energy
  40.     local number = (currentEnergy - TARGET_AMOUNT)
  41.    
  42.     if (number > 0) then
  43.         controlLevel = controlLevel + 5
  44.     elseif(number < 0 ) then
  45.         controlLevel = controlLevel - 5
  46.     end
  47.    
  48.     if (controlLevel < 0) then
  49.         controlLevel = 0
  50.     elseif (controlLevel > 100) then
  51.         controlLevel = 100
  52.     end
  53.     reactor.setAllControlRodLevels(controlLevel)
  54.    
  55.     --Check reactor
  56.     if(reactor.getFuelAmount() == 0)then
  57.         redstone.setOutput("right", true)
  58.         print("Control Rods complety Open")
  59.     elseif (controlLevel == 100) then
  60.         redstone.setOutput("right", true)
  61.         print("Control Rods complety Inserted")
  62.     end
  63.    
  64.     sleep(3)
  65. end
Add Comment
Please, Sign In to add comment