Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local reactor = peripheral.wrap("back")
- local maxEnergy = 10000000.0
- local lowerThreshold = 25.0
- local upperThreshold = 90.0
- local temperatureThreshold = 700
- function computePercent()
- return 100.0 * reactor.getEnergyStored() / maxEnergy
- end
- function powerState()
- if computePercent() < lowerThreshold then
- return -1
- elseif computePercent() < upperThreshold then
- return 0
- else
- return 1
- end
- end
- function activate()
- print("Powering up reactor [" .. computePercent() .. "%] (" .. reactor.getTemperature() .. " C)")
- reactor.setActive(true)
- end
- function deactivate()
- print("Powering down reactor [" .. computePercent() .. "%] (" .. reactor.getTemperature() .. " C)")
- reactor.setActive(false)
- end
- print("Starting energy: " .. computePercent() .. "%")
- if powerState() < 0 then
- activate()
- elseif powerState() > 0 then
- deactivate()
- end
- while true do
- if powerState() < 0 then
- while powerState() < 1 do
- if reactor.getTemperature() > temperatureThreshold and reactor.getActive() then
- deactivate()
- sleep(5)
- else
- if not reactor.getActive() then
- activate()
- end
- sleep(1)
- end
- end
- elseif powerState() > 0 then
- if reactor.getActive() then
- deactivate()
- end
- sleep(20)
- else
- sleep(10)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement