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

Bypassing The Wait For Rednet.receive()

Started by Papa_Beans, 21 November 2013 - 11:12 AM
Papa_Beans #1
Posted 21 November 2013 - 12:12 PM
Hey guys! I am having an issue with my program. The computer is waiting for the responce message back from the turtle, so it never continues! How can I pass the wait time? Would a try catch work? Thanks! If you need the code tell me and I will upload around 5PM EST.
Lyqyd #2
Posted 21 November 2013 - 02:12 PM
You should upload the code. You'll probably want to have a basic event handling loop that looks for rednet_message events as well.
TheOddByte #3
Posted 21 November 2013 - 02:25 PM
Well.. You do know that the rednet.receive() has a timeout right?
EXAMPLE

local timeout = 5

id, msg = rednet.receive(timeout)
if id == nil then
	print("You haven't received any messages D:")
else
	print(id .. ":" .. msg)
end

But as mentioned by Lyqyd you'll probably want to use basic event handling
EXAMPLE

while true do
local evt, id, msg = os.pullEvent()
	if evt == "rednet_message" then
		print(id .. ":" .. msg)
	end
end
Edited on 21 November 2013 - 01:26 PM
Papa_Beans #4
Posted 21 November 2013 - 06:52 PM
Well.. You do know that the rednet.receive() has a timeout right?
EXAMPLE

local timeout = 5

id, msg = rednet.receive(timeout)
if id == nil then
	print("You haven't received any messages D:")
else
	print(id .. ":" .. msg)
end

But as mentioned by Lyqyd you'll probably want to use basic event handling
EXAMPLE

while true do
local evt, id, msg = os.pullEvent()
	if evt == "rednet_message" then
		print(id .. ":" .. msg)
	end
end


Thank you very much, I did not know that rednet had a time out function. I have terrible internet where I live and just learned about rednet, it is tons of fun! I +1'd you, thank you for your time. ~Papa Beans
theoriginalbit #5
Posted 21 November 2013 - 08:41 PM
Also just as a side point. There is not try/catch in Lua.
Papa_Beans #6
Posted 22 November 2013 - 01:56 PM
Also just as a side point. There is not try/catch in Lua.

Thanks xP too much VB haha.