Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --imports
- local component = require("component")
- local event = require("event")
- local serialization = require("serialization")
- local serviceAddress = "df9274d2-2db6-4cda-921c-47564aeb0aa6"
- local servicePort = 1
- local function callService(message, expectAnswer)
- local answer = nil
- component.modem.send(serviceAddress, servicePort, serialization.serialize(message))
- if (expectAnswer == true) then
- local _,_,from,port,_,ans = event.pull("modem_message")
- answer = serialization.unserialize(ans)
- return answer
- end
- return nil
- end
- --main program starts here...
- local function getEnergyPercentage()
- return callService({"getEnergyPercentage"},true)[1]
- end
- local function getReactorStatus()
- return callService({"getReactorStatus"},true)[1]
- end
- local function setReactorStatus(status)
- callService({"setReactorStatus",status},false)
- end
- --program
- local tmp = 0
- while true do
- tmp = tmp + 1
- local reactorStatus = getReactorStatus()
- local percentageFilled = getEnergyPercentage()
- print("Percentage filled: " .. percentageFilled)
- local newReactorStatus = reactorStatus
- if (reactorStatus == false)
- then
- if (percentageFilled < 25)
- then
- newReactorStatus = true
- else
- newReactorStatus = false
- end
- else
- if (percentageFilled > 80)
- then
- newReactorStatus = false
- else
- newReactorStatus = true
- end
- end
- if(reactorStatus ~= newReactorStatus)
- then
- setReactorStatus(newReactorStatus)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement