Hello, i have an obscure problem in my first game. I have a random runtime error after a while in the game.
Pico-8 say : runtime error Attempt to perform arithmetic on field '?' (a nil value)
It's in this function :
for i=1, niv do
if (test==1) niv+=1
I don't understand why this problem triggered.
can you help me ?
To have the bug, play to the game a little and wait a few minutes.
if you can test the game, the but is to find the secret code.
For this, choose 5 colors (maybe the same) and clic to the green button for validate.
if you have a yellow: it's a good color at the wrong place. a green it's a good color at the good place.
Touch "x" for reload the game.
Thanks you for your Help.
PatateaFrite a French Guy with a broken english. :)
Here's the cause of the bug: in your couleur_plus() function, you have this code:
if (test==1) niv+=1 test+=1
This is run inside a for loop many times per frame, so it's not the best code for something that you only want to happen once. But the reason for the crash is that Pico8 has a limit for all numbers of 32767, and then they wrap back around to -32768 when you add 1 to them. Because of this, test+=1 will eventually make test==1 again after a few minutes, and niv+=1 will happen twice.
The solution is to remove this code from the for loop and just put something like niv=2 at the end of the function. I'd have to look at the code more to know what value niv should be, but hopefully this helps you fix that value yourself.
[Please log in to post a comment]