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

smart rednet receive?

Started by pofferman, 21 December 2015 - 05:56 PM
pofferman #1
Posted 21 December 2015 - 06:56 PM
Is there any smart rednet receive trick, for receiveing more than 1 rednet signal at once?

Like if i were to broadcast("Hello there.")
And then all the other 5 computers could send a reply at the same time "Well hello there newcommoner!".
And then my computer would be able to print out all the 5 different recesves.

Any help is appreciated. Thanks
Lupus590 #2
Posted 21 December 2015 - 07:16 PM
rednet also triggers events (in fact rednet.receive is just waiting to receive one of these events)

so if you listen for rednet events manually and print the message yourself, you should be good.


while true do
  local event = {os.pullEvent()}
  --#if event == rednetEvent then
	--#print the message
  else
	--#do something else
  end
end

due to the nature of CC you can't actually receive multiple events at the same time
This is (somewhat) related to the fact that no 2 CC computers run at the same time, only one computer runs, then it pauses to allow another to run.
Edited on 21 December 2015 - 06:20 PM
TheOddByte #3
Posted 21 December 2015 - 07:24 PM

  --#if event == rednetEvent then
Seems like you accidentally added a comment there, and have you forgotten the event for a rednet message aswell? :P/>

if event[1] == "rednet_message" then
Edited on 21 December 2015 - 08:17 PM
Lupus590 #4
Posted 21 December 2015 - 07:32 PM

  --#if event == rednetEvent then
Seems like you accidentally added a comment there, and have you forgotten the event for a rednet message aswell? :P/>

if event == "rednet_message" then

thanks, but that's pseudo-code, also you would need to index that table
pofferman #5
Posted 21 December 2015 - 08:25 PM
So if i listen to the pullEvent instead, i will be able to receive all the messages without anyone of them lost into the deep dark void of nothing?
Lupus590 #6
Posted 21 December 2015 - 09:16 PM
os.pull event will give you one message
you will need to keep pulling events until there are no more rednet events
TheOddByte #7
Posted 21 December 2015 - 09:23 PM

  --#if event == rednetEvent then
Seems like you accidentally added a comment there, and have you forgotten the event for a rednet message aswell? :P/>

if event == "rednet_message" then

thanks, but that's pseudo-code, also you would need to index that table
Woops, fixed that
So if i listen to the pullEvent instead, i will be able to receive all the messages without anyone of them lost into the deep dark void of nothing?
Well yes, using pullEvent will let you get every message because it triggers an event every time a message has been received
But that's also the reason you'd want to put it in a loop, because the function only returns one event.

Here's an exampleIf you did this

local e = { os.pullEvent( "rednet_message" ) }
print( "ID: " .. e[2] .. " | Message : " .. e[3] )
it would only return one message because the os.pullEvent function was only called one time, but if you did this for example

while true do
    local e = { os.pullEvent( "rednet_message" ) }
    print( "ID: " .. e[2] .. " | Message: " .. e[3] )
end
it would catch all messages received, because just as soon as the message has been received and the loop is done it will wait for another event again
pofferman #8
Posted 22 December 2015 - 04:11 PM
So the rednet_message will get stacked in some sort of buffer until its used, in a short time?
Correct me if im wrong.
KingofGamesYami #9
Posted 22 December 2015 - 04:32 PM
So the rednet_message will get stacked in some sort of buffer until its used, in a short time?
Correct me if im wrong.

All events stack in this way, in the event queue. AFAIK it is not timed, although there is a limit of 255 events in the queue. It's not really until it's used, more of until the program requests an event (yields).
pofferman #10
Posted 22 December 2015 - 05:00 PM
Oke thanks, will tests your feedback when i can :)/> ty.
pofferman #11
Posted 22 December 2015 - 06:05 PM
It worked. :)/> Thank you guys for the help :D/>