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

How to timeout a program after x amount of time

Started by diamondpumpkin, 29 May 2015 - 08:28 PM
diamondpumpkin #1
Posted 29 May 2015 - 10:28 PM
I'm setting up a system where I need the program to terminate itself after 10 seconds. I'm using rednet api, when the signal is not sent it's just stuck waiting for it to come by. But I want it to stop listening for that protocol and reboot the computer after 10 seconds. With rednet I can't just put senderID, message = rednet.receive("protocol",10) because that would run all the other lines of code after it, which is not what I want. Little help?…
MKlegoman357 #2
Posted 29 May 2015 - 10:31 PM
If you pass a timeout to rednet.receive and it doesn't get any messages it will return nil, meaning you can check if it timeout:


local id, message = rednet.receive(5)

if id then --# if id is not nil or false
  --# we got a message!
else
  --# no message, rednet.receive timeout
end
diamondpumpkin #3
Posted 29 May 2015 - 10:35 PM
Thanks!