Log In  

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?

P#22695 2016-06-11 17:17 ( Edited 2016-06-19 15:43)

Can you post your cart so we can look at the code?

P#22716 2016-06-11 20:45 ( Edited 2016-06-12 00:45)

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.

P#22719 2016-06-11 22:07 ( Edited 2016-06-12 02:07)

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.

P#22722 2016-06-12 01:59 ( Edited 2016-06-12 05:59)

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.

P#22723 2016-06-12 02:21 ( Edited 2016-06-12 06:21)

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...

P#22724 2016-06-12 02:38 ( Edited 2016-06-12 06:38)

I reported this two weeks ago (so far no response): https://www.lexaloffle.com/bbs/?tid=3509

Agreed that it's a hazard.

P#22776 2016-06-12 18:08 ( Edited 2016-06-12 22:08)

@Felice: Sadly it is not true, that I save tokens from there, as I have to put the condition into brackets then...

P#23178 2016-06-19 03:06 ( Edited 2016-06-19 07:09)

@SunSailor:

Sorry, when I was testing the token count, apparently I was caught by an editor bug that adds phantom tokens on copy/paste.

(See here for details.)

P#23207 2016-06-19 11:43 ( Edited 2016-06-19 15:46)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-29 06:56:24 | 0.012s | Q:23