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

[1.47][SSP] Coroutine with rednet.receive

Started by maximal, 05 December 2012 - 08:39 AM
maximal #1
Posted 05 December 2012 - 09:39 AM
i tried to make a coroutine to receive rednet messages but get wrong values. I tested it on wireless turtle.

function f()
while true do
coroutine.yield(rednet.receive())
end
end

rednet.open("right")

c = coroutine.create(f)

coroutine.resume© //getting "true rednet_message" here regardless of was there any messages or not

I leaned about lua just yesterday so i can do something wrong here.

Thanks.
immibis #2
Posted 06 December 2012 - 02:40 PM
Internally, events use coroutines - specifically os.pullEventRaw is the same as coroutine.yield.
You can't pass events to coroutines unless you do it yourself or use parallel to handle it for you.
Cloudy #3
Posted 06 December 2012 - 09:02 PM
Read the Lua manual and start again. Or ask in Ask A Pro, not the bug forum.