SHOW:
|
|
- or go back to the newest paste.
| 1 | -- Connect to a reactor on the back port of the computer | |
| 2 | local reactor = peripheral.wrap("back")
| |
| 3 | ||
| 4 | -- Max level is fixed for all reactor sizes? | |
| 5 | local reactorMaxEnergyCapacity = 10000000 | |
| 6 | ||
| 7 | -- initialize variables outsize loop. marginally more efficient server side | |
| 8 | local reactorStoredEnergy = 0 | |
| 9 | local reactorStoredEnergyPercentage = 0 | |
| 10 | ||
| 11 | -- While true is an endless loop | |
| 12 | while true do | |
| 13 | -- Get the amount of RF stored in the reactor | |
| 14 | reactorStoredEnergy = reactor.getEnergyStored() | |
| 15 | ||
| 16 | -- Calculate the percentage of energy stored | |
| 17 | reactorStoredEnergyPercentage = (reactorStoredEnergy/reactorMaxEnergyCapacity)*100 | |
| 18 | ||
| 19 | -- Print to screen an informational message | |
| 20 | - | -- tur it on |
| 20 | + | |
| 21 | ||
| 22 | -- If the reactor is active AND % of stored energy is 99 or above | |
| 23 | if reactor.getActive() and reactorStoredEnergyPercentage >= 99 then | |
| 24 | -- turn off the reactor | |
| 25 | - | -- Sleep for aproximately 20 ticks so we don't |
| 25 | + | |
| 26 | - | -- Overload the server unnecessarily |
| 26 | + | |
| 27 | elseif not reactor.getActive() and reactorStoredEnergyPercentage < 99 then | |
| 28 | -- otherwise IF the reactor is not active AND stored RF below 99% | |
| 29 | -- turn reactor on | |
| 30 | print("Turning reactor on")
| |
| 31 | reactor.setActive(true) | |
| 32 | end | |
| 33 | ||
| 34 | -- Sleep for aproximately 20 ticks so we don't Overload the server unnecessarily | |
| 35 | os.sleep(1) | |
| 36 | end |