Advertisement
maxheyer

Untitled

Jan 4th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.78 KB | None | 0 0
  1. local commands = {
  2.   collect = function()
  3.     modem.broadcast(port, "ping")
  4.  
  5.     print("Collecting devices...")
  6.     local function registerDevice(signal, _, remoteAddress, _, _, payload)
  7.       print(remoteAddress)
  8.       devices.insert(remoteAddress)
  9.       print(devices)
  10.     end
  11.  
  12.     event.listen("modem_message", registerDevice)
  13.     event.timer(5, function()
  14.       event.ignore("modem_message", registerDevice)
  15.       event.push("command_executed")
  16.       print(#devices .. " devices found!")
  17.     end)
  18.   end
  19. }
  20.  
  21. while true do
  22.   local input = io.read()
  23.  
  24.   if input == "quit" or input == "q" then quit() end
  25.  
  26.   if commands[input] == nil then
  27.     print("Command not found!")
  28.   else
  29.     pcall(commands[input])
  30.     event.pull("command_executed")
  31.     print("")
  32.   end
  33. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement