Advertisement
jaypar

Controller

Aug 17th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.79 KB | None | 0 0
  1. modem = peripheral.find("modem")
  2.  
  3. if not modem.isOpen(1298) then
  4.     modem.open(1298)
  5. end
  6.  
  7. function Sender()
  8.     while true do
  9.         Send(io.read(), 1297)
  10.     end
  11. end
  12.  
  13. function Send(msg, channel)
  14.     modem.transmit(channel, 1298, string.char(12, 97) .. msg)
  15. end
  16.  
  17. function Listen()
  18.     while true do
  19.         local _, _, _, replyChan, m, _ = os.pullEvent("modem_message")
  20.        
  21.         if string.find(m, string.char(12, 97)) then
  22.             local formattedMessage = string.sub(m, 3)
  23.             print(m .. " turned into " .. formattedMessage)
  24.         else
  25.             Reply("This is not the modem you are looking for!", replyChan)
  26.         end
  27.     end
  28. end
  29.  
  30. function Reply(msg, replyChannel)
  31.     print("Reply sent to " .. replyChannel .. " with message \"" .. msg .. "\"")
  32.     modem.transmit(replyChannel, 1297, msg)
  33. end
  34.  
  35. parallel.waitForAll(Sender, Listen)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement