Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enabled = true
- function ack(comm, success)
- local out = ""
- if success == true then
- out = string.format("%s %s %s ack", comm[1], comm[0], comm[2])
- elseif success == false then
- out = string.format("%s %s %s nack", comm[1], comm[0], comm[2])
- end
- rednet.broadcast(out, "LightControl")
- end
- function process(comm)
- if comm[3] == "on" then
- rs.setOutput(comm[2], true)
- if rs.getOutput(comm[2]) == true then
- print(string.format("Host %s activated lights on %s side", comm[0], comm[2]))
- ack(comm, true)
- else
- print(string.format("Host %s attempted to activate lights on %s side. An error occurred.", comm[0], comm[2]))
- ack(comm, false)
- end
- elseif comm[3] == "off" then
- rs.setOutput(comm[2], false)
- if rs.getOutput(comm[2]) == false then
- print(string.format("Host %s deactivated lights on %s side", comm[0], comm[2]))
- ack(comm, true)
- else
- print(string.format("Host %s attempted to deactivate lights on %s side. An error occurred", comm[0], comm[2]))
- ack(comm, false)
- end
- elseif comm[3] == "state" then
- out = string.format("%s %s %s %s", comm[1], comm[0], comm[2], tostring(rs.getOutput(comm[2])))
- rednet.broadcast(out, "LightControl")
- else
- print(string.format("Host %s issued an invalid command: %s %s", comm[0], comm[2], comm[3]))
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement