questions about task_complete event uppon calling .list() or .size() #2447
-
|
I got a co-routine that calls my_peripheral.list() what is the intended way to handle this? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 3 replies
-
|
Without knowing your actual code, there's no real advice I can give you about this other than just... Ignore the event? Could you post your code? |
Beta Was this translation helpful? Give feedback.
-
|
Oh, hold on, I missed the part about a coroutine. Coroutines should receive events based on three filters:
I recommend against working with raw coroutines though, especially if you aren't entirely sure how the event system works. Instead, use the |
Beta Was this translation helpful? Give feedback.
-
|
here is a minimal (but verbose example i threw together to show the issue) local function foo()
local a = peripheral.wrap("left")
print("-- Wrapped peripheral")
a.list()
print("-- Unreachable")
end
local co = coroutine.create(foo)
print("-- Created Coroutine")
coroutine.resume(co)
print("-- Coroutine yeilded")
local event = { os.pullEvent() }
print("Got event ".. event[1])Output: -- Created Coroutine
-- Wrapped peripheral
-- Coroutine yeilded |
Beta Was this translation helpful? Give feedback.
-
|
I do understand that calling .list() yields, |
Beta Was this translation helpful? Give feedback.
-
|
Yes, just catching the event is not enough. You need to actually send the event back to the coroutine again, via coroutine.resume(co, table.unpack(event)) -- passes the event to the coroutineAgain, highly recommend looking at how But I believe you may also be getting stuck on another hiccup of coroutines... Coroutines are not Threads. They do not run in the background. Lua is single-threaded, and so everything runs sequentially. Calling |
Beta Was this translation helpful? Give feedback.
Yes, just catching the event is not enough. You need to actually send the event back to the coroutine again, via
coroutine.resume.Again, highly recommend looking at how
paralleldoes it, or just usingparallelinstead of running your own coroutine library. There's a lot of small issues that can occur when working manually with coroutines.But I believe you may also be getting stuck on another hiccup of coroutines... Coroutines are not Threads. They do not run in the background. Lua is single-threaded, and so everything runs sequentially. Calling
coroutine.resumeactually switches to running your coroutine, the…