I was trying to replace a for-loop with coroutines to move the stars:
--fine
function _update()
for c in all(boids) do
move_boid(c)
end
end
--broken
function _update()
for c in all(boids) do
coresume(cocreate(move_boid),c)
end
end
Notice that a fixed number of stars are frozen (I'm pretty sure the number is fixed):
But why? How can I handle this? The complete code is on itch.
Thanks for @Vald and @Egor's comments. Seems the problem is caused by "too-long coroutines" to finish in a PICO-8 cycle. So the solution is that I store unfinished coroutines in a table and resume them if not finished. But somehow the movement is changed, kinda like "lost frame".
Here's my edited code:
And also modify the calculation function, adding a new line in the middle:
Just to yield before it's completed.
Update: another way to do it is reusing coroutines.