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

Checking if rednet receive has timed out?

Started by Jasonfran, 05 December 2012 - 07:37 AM
Jasonfran #1
Posted 05 December 2012 - 08:37 AM
How do you check if the rednet receive timed out. I have it set up properly to get messages but I can't find how to find out when it times out so I can do something.
Cranium #2
Posted 05 December 2012 - 08:41 AM
If you use rednet.receive() with no arguments, it will continue forever until it receives a rednet message of any kind. Using rednet.receive(timeout) will allow you to use a specific timeout period. Say… (5) seconds.
Jasonfran #3
Posted 05 December 2012 - 08:49 AM
If you use rednet.receive() with no arguments, it will continue forever until it receives a rednet message of any kind. Using rednet.receive(timeout) will allow you to use a specific timeout period. Say… (5) seconds.
I know that, I was just wondering how you check when it has timed out. But I think I got it as the message is returned as nothing
Cranium #4
Posted 05 December 2012 - 09:13 AM
The only thing you can do is check like this:

local id, msg, dist = rednet.receive(5)
if not msg then
    print("message not received")
else
--do other stuff
end