Advertisement
Guest User

LightCtrl

a guest
Jan 26th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.36 KB | None | 0 0
  1. enabled = true
  2.  
  3. function ack(comm, success)
  4.   local out = ""
  5.   if success == true then
  6.     out = string.format("%s %s %s ack", comm[1], comm[0], comm[2])
  7.   elseif success == false then
  8.     out = string.format("%s %s %s nack", comm[1], comm[0], comm[2])
  9.   end
  10.   rednet.broadcast(out, "LightControl")
  11. end
  12.  
  13. function process(comm)
  14.   if comm[3] == "on" then
  15.     rs.setOutput(comm[2], true)
  16.     if rs.getOutput(comm[2]) == true then
  17.       print(string.format("Host %s activated lights on %s side", comm[0], comm[2]))
  18.       ack(comm, true)
  19.     else
  20.       print(string.format("Host %s attempted to activate lights on %s side.  An error occurred.", comm[0], comm[2]))    
  21.       ack(comm, false)
  22.     end
  23.   elseif comm[3] == "off" then
  24.     rs.setOutput(comm[2], false)
  25.     if rs.getOutput(comm[2]) == false then
  26.       print(string.format("Host %s deactivated lights on %s side", comm[0], comm[2]))
  27.       ack(comm, true)
  28.     else
  29.       print(string.format("Host %s attempted to deactivate lights on %s side.  An error occurred", comm[0], comm[2]))
  30.       ack(comm, false)
  31.     end
  32.   elseif comm[3] == "state" then
  33.     out = string.format("%s %s %s %s", comm[1], comm[0], comm[2], tostring(rs.getOutput(comm[2])))
  34.     rednet.broadcast(out, "LightControl")
  35.   else
  36.     print(string.format("Host %s issued an invalid command: %s %s", comm[0], comm[2], comm[3]))
  37.   end
  38. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement