I’m quite confuse how to use coroutine.resume on a loop.
example
local function loop()
for i, v in pairs(table) do
--code
coroutine.yield()
end
local loopfunction = coroutine.create(loop)
coroutine.resume(loopfunction)
So the thing that I’m stuck on, is that when there’s only one coroutine.resume, it would run the code once or twice or smth, that’s the problem, if I loop on a table and I don’t know how much time it would loop though, what do I do with coroutine?
it’s pretty simple, you just gotta call the function in the coroutine.
local function loop()
for i, v in pairs(table) do
--code
end
end
local loopfunction = coroutine.create(loop)
loop()
end)
coroutine.resume(loopfunction)
function yield(barf)
coroutine.yield(barf)
end
local foo do
local function bar()
for i = 1, 10 do
print('hello nothing')
end
yield(foo)
end
foo = coroutine.create(bar)
end
coroutine.resume(foo)