Hi,
I'm using coroutines very successfully in my battle system. The only drawback now is, that coroutines don't stop the game, nor do they throw or show any errors. This is very, very unpleasant, as I'm having some of my core logic in there. If there is an error, the game simply stops, because it expects a result in a table. I don't have any hint what went wrong in that case and debugging this takes a lot of frustrating time - any chance to fix that?
No, as you wouldn't get far by analyzing that monster of code, but I made a sample, which shows the effect as well:
function oncoroutine() byield=byield or cocreate(function () print("a test") yield() print(g.make.error) yield() print("continue.") end) if costatus(byield) then coresume(byield) else print("error!") end end print("first:") oncoroutine() print("second:") oncoroutine() print("third:") oncoroutine() |
It is very simple, it forces an error in the second yield run by accessing a non existent value.
Slightly off-topic, but just wanted to mention that you can save two tokens (then+end) in similar code if you typically put your if/else on one line:
if costatus(byield) coresume(byield) else print("error!") |
Pardon if you already knew about this PICO-8 Lua feature. Also pardon for OT comment. I don't have any info on the coroutine issue, sorry, but you're right that it needs fixing because I'm now rapidly losing interest in the plan I had to use them. I write buggy code. :) PICO-8 is hard enough to debug as it is.
Actually, a thought on a stopgap to help debug in such cases...
Where you have your loop that resumes all active coroutines this frame, you could use a PRINTH() call to spew to the host console about which coroutine is taking over:
That at least helps narrow it down until you get a fix in 0.1.7 or something.
Thanks for the input - yes, I know about the shorter writing, but I'm not really used to it. I definitely need to overwhaul the code with this, there should be a bunch of tokens I can save from there. Thanks for reminding!
On the other hand - having printh only helps to narrow down the issue a bit, I mostly use a global debug_name=name declaration to achieve this, but printh eats tokens as well, afaik. And tokens are the only resource I don't have enough at all ;), currently I'm at 7853 tokens...
I reported this two weeks ago (so far no response): https://www.lexaloffle.com/bbs/?tid=3509
Agreed that it's a hazard.
[Please log in to post a comment]