Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modemSide = "right"
- local reactorSide = "left"
- local broadcastProtocol = "reactor"
- local receiveProtocol = "reactor_talk"
- local reactor = nil
- local maxEnergy = 10000000
- -- this application broadcasts using the protocols of reactor
- function init()
- if os.getComputerLabel() == nil then
- os.setComputerLabel(os.getComputerID())
- print("No label was set for this computer, one was created.. "..os.getComputerLabel())
- end
- print("openning network on right side")
- rednet.open(modemSide)
- reactor = peripheral.wrap(reactorSide)
- end
- function backend_command()
- local id, msg = rednet.receive(receiveProtocol)
- if msg == "coma" then
- sleep(60 * 10)
- reactor.setActive(false)
- os.shutdown()
- end
- end
- function check()
- if reactor.getEnergyStored() > maxEnergy / 2 then
- reactor.setActive(false)
- elseif reactor.getEnergyStored() < maxEnergy / 8 then
- reactor.setActive(true)
- end
- end
- function run()
- init()
- while true do
- check()
- local packet = {
- ["current"] = reactor.getEnergyStored(),
- ["max"] = maxEnergy, ['active'] = reactor.getActive()
- }
- rednet.broadcast(packet, broadcastProtocol)
- sleep(.5)
- end
- end
- parallel.waitForAll(run, backend_command)
Add Comment
Please, Sign In to add comment