Receiving a rednet message through os.pullEvent()

From ComputerCraft Wiki
Revision as of 13:41, 17 July 2012 by 188.143.232.12 (Talk) (Explanation)

Jump to: navigation, search

The following method is a good method of receiving a rednet message without using rednet.receive(). It is usually used in IRC, Chat programs e.t.c. When a message arrives to a computer, a "rednet_message" event occurs.

The Code

This is a typical Listener which prints the content and the sender id of any incoming message.

rednet.open("Direction_of_modem")
while true do
  event, id, text = os.pullEvent()
  if event == "rednet_message" then
    print(id .. "> " .. text)
  end
end

What a pleasure to find soemone who identifies the issues so clearly