This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
htothe2oh's profile picture

Filtering rednet.receive()

Started by htothe2oh, 11 October 2012 - 01:57 AM
htothe2oh #1
Posted 11 October 2012 - 03:57 AM
basically what i want is a way to only receive messages from a certain computer sometimes, so i can ping them. If there is a build in way to ping, please tell, but otherwise I pretty much need a way to make it so that rednet.receive() is only accepting messages from a certain computer ID

thanks,
Htothe2oh
Luanub #2
Posted 11 October 2012 - 04:23 AM
ping:
computer A:

rednet.send(toID,"ping")

computer B:

local id, msg = rednet.receive()
if msg == "ping" then
  rednet.send(id,"pong")
end


Filter:

local tAccepted = {1,2,3} --change to id's that you want to accept from
local id, msg = rednet.receive()
for x=1, #tAccepted do
  if id == tAccepted[x] then
    -- its good
  else
    -- its bad
  end
end