anfbckdo

receiver.lua

Dec 21st, 2023 (edited)
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.05 KB | None | 0 0
  1. local modem = peripheral.find("modem") or error("No modem found!", 0) -- checks for modem
  2.  
  3. write("Recieving Channel (0-65535): ") -- asks user for input
  4.  
  5.     recieveChannel = read()
  6.  
  7.     recieveChannelInt = tonumber(recieveChannel) -- defines the recieveChannel as an integer, as modem.open can only handle integer input.
  8.  
  9.     print("Opening channel " .. recieveChannelInt .. "...")
  10.    
  11.     modem.open(recieveChannelInt)
  12.  
  13.     print("Channel " .. recieveChannelInt .. " open.")
  14.     while true do
  15.     local event, side, channel, replyChannel, message, distance -- defines vars, the channel variable here is from the computer contacting us from a channel (x).
  16.     repeat
  17.         event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
  18.     until channel == recieveChannelInt -- puts variables into event until the channel variable is equal to the recieving channels variable. This helps prevent spoofing and allows messages from a certain channel.
  19.      print("Recieved a reply from " .. tostring(message))  -- prints a reply
  20. end
Advertisement
Add Comment
Please, Sign In to add comment