Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- https://www.lua.org/pil/20.3.html
- -- http://lua-users.org/wiki/PatternsTutorial
- local reactor = peripheral.find("BigReactors-Reactor")
- local modem = peripheral.wrap("top")
- local channel = 24816
- modem.open(channel)
- local drawer = peripheral.find("drawer")
- --calculates run time based on fuel
- function calcRunTime(fuelLevel)
- print("calc run time")
- --(fuel level in mb / consumption rate in mb/t) / ticks per second
- -- mb t s
- -- ___ * ___ * ___ = s
- -- 1 mb t
- return ((fuelLevel / reactor.getFuelConsumedLastTick()) / 20)
- end
- --calculates total fuel available in both reactor and storage
- function calcFuelLevel()
- print("calc fuel level")
- return ((drawer.getItemCount(1) * 1000) + reactor.getFuelAmount())
- end
- --estimates total power producable with current fuel
- function calcTotalPower()
- print("calc total power")
- return (calcRunTime(calcFuelLevel()) * 20 * reactor.getEnergyProducedLastTick())
- end
- --main loop. transmits fuel level and runtime estimate over wireless
- while true do
- local fuelLevel = calcFuelLevel()
- local runTime = calcRunTime(fuelLevel)
- local totalPower = calcTotalPower()
- modem.transmit(channel, 3, fuelLevel)
- os.sleep(1)
- modem.transmit(channel, 4, runTime)
- os.sleep(1)
- modem.transmit(channel, 5, totalPower)
- os.sleep(5)
- end
Add Comment
Please, Sign In to add comment