Calling peripheral.wrap on an inventory and calling the list method in a coroutine seems to have an odd behaviour
Shiranuit opened this issue ยท 0 comments
Minecraft Version
1.19.x
Version
[1.19.2] 1.101.1
Details
I'm not sure if this is a bug or I'm not understanding how this works
If you are placing a chest next to a computer and wrap it as a peripheral.
Then you try to call the list
method of the inventory peripheral inside a coroutine, which yields the coroutine.
The first call to coroutine.resume then return true, "task_complete"
which means a task_complete
event has been emitted and contains the result of the call to list
.
There are multiple thing that seems odd:
- When the call to
list()
occurs it yield withtask_complete
but does not give atask_id
which means if there are multipletask_complete
event we cannot know which result belong to our coroutine - Resuming the coroutine after that doesn't do anything, even though there is still code that needs to be executed after the first yield
- The coroutine is marked as
suspended
and doesn't seems to end at any point in time after
I tried to find what could be causing this in the source code but wasn't able to find if this was intended or not, I didn't have much time to look deeply into it.
local p = peripheral.wrap("right") -- chest
local co = coroutine.create(function()
print("before") -- Print "before"
local list = p.list() -- Yields the coroutine
print("after") -- Unfortunately does not come here event after resuming the coroutine another time
for k, v in pairs(list) do
print(k, v)
end
end)
print(coroutine.resume(co)) -- success, task_complete
local event, task_id, success, list = os.pullEvent("task_complete")
print(coroutine.status(co)) -- suspended
coroutine.resume(co, list) -- resumes the coroutine with the obtained list of items, but nothing happens