Flip Me Off

Published 2023-06-12


You ever have that moment when somebody tells you something and you SORT OF get it but not really, and then later, maybe a day or two you cry out, "Ah ha !" because then you understand it ?

Well I'm not going to claim full knowledge of the YIELD() command, but I will tell you what it CAN do - at least for me.

I can take any program I've written to date and make it OOPS very simply.

Replace all FLIP() with YIELD(), then make a coroutine to run my MAIN() function. Done.

But it goes beyond this. Since I can now join the ranks of _DRAW() and _UPDATE() this means I can write a custom background engine that operates exactly as I like it.

In this case for this example you can hit "Q" and bring up Quick Debugger which shows memory usage and how much of the CPU is being tasked. You can also hit [ESC] and type RESUME to leave off where you where.

Before YIELD() I couldn't do either of these things nor read the CPU. Now I can. This does herald the END of FLIP() for me and the very welcome arrival of YIELD().

What does this mean for you ? YIELD() does not just exit a function it retains the exact position when you return even if you were nested in a whirl of FOR/DO, IF/END, and REPEAT/UNTIL statements. It also retains all local variables and values at the point you exit and return. That is immensely powerful.

Giving credit where credit is due. I found out about YIELD() from freds72 HERE:
https://www.lexaloffle.com/bbs/?tid=31359

and MBoffin HERE:

https://www.lexaloffle.com/bbs/?tid=35381

. . .

More and more I begin to appreciate this Pico-8 system and daresay it is the most powerful programming language I have ever come across.