For Saken

Published 2023-06-12

By looking at this code you would think the end result would be 4 each time, both in the function and in the main program as most programming languages would return that value. But this is not the case with PICO-8. Instead the result will be what you defined globally, in this case 6.

So it's important to remember that the index variable in ANY FOR/END statements, either directly in your main code or in a function - will ALWAYS be local to the loop.

So you need NEVER define LOCAL variables in a function that will only be used in FOR/END statements. Good to know.

Here is the cart for examination: