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
2427 posts
Location
UK
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
1852 posts
Location
Sweden
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
2427 posts
Location
UK
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
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?
2427 posts
Location
UK
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
1852 posts
Location
Sweden
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 example
If 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
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.
3057 posts
Location
United States of America
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).
37 posts
Posted 22 December 2015 - 05:00 PM
Oke thanks, will tests your feedback when i can :)/> ty.
37 posts
Posted 22 December 2015 - 06:05 PM
It worked. :)/> Thank you guys for the help :D/>