Advertisement
Guest User

startup

a guest
Oct 1st, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.92 KB | None | 0 0
  1. local reactor = peripheral.wrap("right")
  2.  
  3. local maxEnergy = 9000000
  4. local lowEnergyThreshold = 5000000
  5. local idleLoops = 0
  6. local maxLoops = 10
  7.  
  8. while true do
  9.  
  10. local curEnergy = reactor.getEnergyStored()
  11.  
  12. local reactorIsActive = reactor.getActive()
  13.  
  14. --if we're low on energy and off, turn reactor on
  15. if curEnergy <= lowEnergyThreshold and not reactorIsActive then
  16. idleLoops = 0
  17. print("Turning on...")
  18. reactor.setActive(true)
  19.  
  20. --if we're past 9M RF, shut us off
  21. --otherwise, do nothing
  22. elseif curEnergy >= maxEnergy then
  23. if reactorisActive then
  24. print("Turning off...")
  25. reactor.setActive(false)
  26. else
  27. print("Idling...")
  28. end
  29.  
  30. end
  31.  
  32. sleep(2)
  33.  
  34. --if we're not running, count idle loops
  35. if not reactorIsActive then
  36. idleLoops = idleLoops + 1
  37. end
  38.  
  39. --if we reach 10 idle loops, "hibernate" the script
  40. if idleLoops >= maxLoops and not reactorIsActive then
  41. print("Hibernating...")
  42. sleep(120)
  43. idleLoops = 0
  44. end
  45.  
  46. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement