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

Receive all rednet messages and processing that information

Started by jebus, 01 February 2013 - 11:05 AM
jebus #1
Posted 01 February 2013 - 12:05 PM
How do I do receive all rednet messages while running another program?

This other program also needs the information being received.

readfunction = function()
while true do
a,b,c=rednet.receive()
*pass relevant information to a queue or something*
end
end

Then start a coroutine with that function or something.
But how do I share this information?

(Maybe just a list with unprocessed messages, checking how many are left, poping the next message etc.)
GravityScore #2
Posted 01 February 2013 - 01:50 PM
This looks like a server sort of program, where you have 1 coroutine receiving messages and another updating a display. You can run 2 functions at the same time with the parallels API.

Code:

local messages = {}

local receive = function()
  while true do
    local sid, smsg, sdis = rednet.receive()
    table.insert(messages, {id = sid, msg = smsg, dis = sdis})
  end
end

local display = function()
  while true do
    -- All messages sent to this computer are stored in the table messages
    -- You could display them here...
    term.clear()
    term.setCursorPos(1, 1)
    for i, v in ipairs(messages) do
      print(i .. ": " v)
    end
    sleep(1)
  end
end

parallel.waitForAny(receive, display)