Jump to content




smart rednet receive?


  • You cannot reply to this topic
10 replies to this topic

#1 pofferman

  • Members
  • 37 posts

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

#2 Lupus590

  • Members
  • 2,028 posts
  • LocationUK

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 by Lupus590, 21 December 2015 - 07:20 PM.


#3 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 21 December 2015 - 07:24 PM

View PostLupus590, on 21 December 2015 - 07:16 PM, said:

  --#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 by TheOddByte, 21 December 2015 - 09:17 PM.


#4 Lupus590

  • Members
  • 2,028 posts
  • LocationUK

Posted 21 December 2015 - 07:32 PM

View PostTheOddByte, on 21 December 2015 - 07:24 PM, said:

View PostLupus590, on 21 December 2015 - 07:16 PM, said:

  --#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

#5 pofferman

  • Members
  • 37 posts

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?

#6 Lupus590

  • Members
  • 2,028 posts
  • LocationUK

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

#7 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 21 December 2015 - 09:23 PM

View PostLupus590, on 21 December 2015 - 07:32 PM, said:

View PostTheOddByte, on 21 December 2015 - 07:24 PM, said:

View PostLupus590, on 21 December 2015 - 07:16 PM, said:

  --#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

View Postpofferman, on 21 December 2015 - 08:25 PM, said:

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 example


#8 pofferman

  • Members
  • 37 posts

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.

#9 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 22 December 2015 - 04:32 PM

View Postpofferman, on 22 December 2015 - 04:11 PM, said:

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).

#10 pofferman

  • Members
  • 37 posts

Posted 22 December 2015 - 05:00 PM

Oke thanks, will tests your feedback when i can :) ty.

#11 pofferman

  • Members
  • 37 posts

Posted 22 December 2015 - 06:05 PM

It worked. :) Thank you guys for the help :D





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users