function wait()
repeat
flip()
until btnp(4)
end
function count()
cls()
for i=1,3 do
print(i)
end
end
i=6
count()
wait()
print("")
print(i)
print("")
wait()
for i=1,3 do
print(i)
end
wait()
print("")
print(i)
print("done!")
repeat
flip()
until forever
|
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:
by dw817
[Please log in to post a comment]




