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

How to find out an ID from a message (Rednet)

Started by Johnathon, 11 April 2013 - 02:46 AM
Johnathon #1
Posted 11 April 2013 - 04:46 AM
Hey guys, bit newbie at Computer craft still and I decided why not work on a complex topic like make a Server chat.


I have a little down set but what I really need to know is it possible when a computer receives a message to see what ID it has came from, and act accordingly a very budget program would be

if ID = 1 then
send back hi

if ID = 2 then
don't send back anything since it came from here.

Excuse the no syntax no nothing, I just want to know if this is possilble.

I hope you understand if not I can write up what I have so far.
SadKingBilly #2
Posted 11 April 2013 - 04:48 AM
id, message, distance = rednet.receive()

rednet.receive() returns three values: the ID of the computer that sent the message, the message itself, and the distance to the transmitting computer. If you only want to store the ID and the message, then you can just do:

id, message = rednet.receive()
Johnathon #3
Posted 11 April 2013 - 04:50 AM
id, message, distance = rednet.receive()

rednet.receive() returns three values: the id of the computer that sent the message, the message itself, and the distance to the transmitting computer.

You just saved me so much research :)/> Thanks a lot
How can I use the "ID" switch to calculate the reply.

Would i go like

if (rednet,receivve().ID == 1) or something similar?
Sammich Lord #4
Posted 11 April 2013 - 04:51 AM

local events = {rednet.receive()}
if events[1] then
  rednet.send(events[1], "hi")
end
That would do what you want.

You just saved me so much research :)/> Thanks a lot
You should visit the wiki before posting in Ask A Pro.