Internal Lua doesn't like when _update and _draw are removed

0
0
Published 2024-08-06

Let's say I have a cartridge that changes game states by swapping out the _update and _draw functions. This way, when I'm at the title screen, the title screen's _draw function is called directly, as it is stored in the global variable named "_draw", and when I switch to the in-game state, the level drawing function moves to "_draw" instead. This reduces logic (and therefore saves precious characters / tokens) since you no longer need to call the function yourself based on what gamestate you're in.

Now, one of those game states is transitional. It doesn't need an _update or _draw function. It exists entirely as an _init function that draws and flips itself for a bit, then changes the gamestate to something else. But since Pico-8 knows that there was an "_update" function before, it still remembers that and tries to call it...

... Which crashes the program script with a Lua error saying that it failed to call _update on a line beyond the end of the program. Fun! :D

I can of course work around this just fine. In fact, with a full implementation I'm sure this problem wouldn't even exist, since flip() would presumably skip the _update and _draw calls until it's done. But this is still a thing worth noting... somewhere. Probably. ^^;

Test cart: