Advertisement
massacring

sendCommand

Feb 1st, 2024 (edited)
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.95 KB | None | 0 0
  1. local modem = peripheral.find("modem") or error("No modem attached", 0)
  2. local channel = 4242
  3. modem.open(channel)
  4.  
  5. local command = arg[1]
  6.  
  7. local switch = function (argument)
  8.     argument = argument and tonumber(argument) or argument
  9.  
  10.     local case =
  11.     {
  12.         reboot = function ()
  13.             modem.transmit(4243, 4242, "reboot")
  14.         end,
  15.         rainbow = function ()
  16.             modem.transmit(4243, 4242, string.format("rainbow-%s", arg[2]))
  17.         end,
  18.         default = function ()
  19.             error("Invalid command", 0)
  20.         end
  21.     }
  22.  
  23.     if case[argument] then
  24.         case[argument]()
  25.     else
  26.         case["default"]()
  27.     end
  28. end
  29.  
  30. switch(command)
  31.  
  32. local event, side, senderChannel, replyChannel, message, distance
  33. repeat
  34.   event, side, senderChannel, replyChannel, message, distance = os.pullEvent("modem_message")
  35. until senderChannel == channel
  36.  
  37. term.clear()
  38. term.setCursorPos(1, 1)
  39.  
  40. print(tostring(message))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement