Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local reactor = peripheral.wrap("right")
- local maxEnergy = 9000000
- local lowEnergyThreshold = 5000000
- local idleLoops = 0
- local maxLoops = 10
- while true do
- local curEnergy = reactor.getEnergyStored()
- local reactorIsActive = reactor.getActive()
- --if we're low on energy and off, turn reactor on
- if curEnergy <= lowEnergyThreshold and not reactorIsActive then
- idleLoops = 0
- print("Turning on...")
- reactor.setActive(true)
- --if we're past 9M RF, shut us off
- --otherwise, do nothing
- elseif curEnergy >= maxEnergy then
- if reactorisActive then
- print("Turning off...")
- reactor.setActive(false)
- else
- print("Idling...")
- end
- end
- sleep(2)
- --if we're not running, count idle loops
- if not reactorIsActive then
- idleLoops = idleLoops + 1
- end
- --if we reach 10 idle loops, "hibernate" the script
- if idleLoops >= maxLoops and not reactorIsActive then
- print("Hibernating...")
- sleep(120)
- idleLoops = 0
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement