Advertisement
osmarks

simple spatial remote

May 11th, 2020
1,048
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.50 KB | None | 0 0
  1. local m = peripheral.find "modem"
  2. local channel = 15215
  3.  
  4. m.open(channel)
  5.  
  6. m.transmit(channel, channel, {"swap"})
  7.  
  8. parallel.waitForAny(function()
  9.     while true do
  10.         local _, _, c, rc, msg = os.pullEvent "modem_message"
  11.         if type(msg) == "table" and c == channel and msg[1] == "swapped" then
  12.             if msg[2] then
  13.                 print "Success!"
  14.                 return
  15.             else
  16.                 printError("Swap failed (reason: " .. msg[3] .. ").")
  17.                 return
  18.             end
  19.         end
  20.     end
  21. end, function()
  22.     sleep(3)
  23.     printError "Timed out."
  24. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement