Log In  


Cart #mastermind-0 | 2020-11-30 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

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 :


function couleur_plus()
for i=1, niv do
rectfill(26,tpy[i],30,tpy[i]+4,tc1[i])
rectfill(35,tpy[i],39,tpy[i]+4,tc2[i])
rectfill(44,tpy[i],48,tpy[i]+4,tc3[i])
rectfill(53,tpy[i],57,tpy[i]+4,tc4[i])
rectfill(62,tpy[i],66,tpy[i]+4,tc5[i])

rectfill(79,tpy[i],83,tpy[i]+4,tv1[i])
rectfill(88,tpy[i],92,tpy[i]+4,tv2[i])
rectfill(97,tpy[i],101,tpy[i]+4,tv3[i])
rectfill(106,tpy[i],110,tpy[i]+4,tv4[i])
rectfill(115,tpy[i],119,tpy[i]+4,tv5[i])

if (test==1) niv+=1
test+=1
end
end

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. :)



The error message should also tell you which line caused the problem. Can you tell us?


Yes the complete code error is :

runtime error line 35 tab 6
rectfill(26,tpy[i],30,tpy[i]+4,tc1[i])
attempt to perform arithmetic on field '?' (a nil value)
in couleur_plus line 35 (tab 6)
in _draw line 27 (tab 0)
at line 0 (tab 0)


tpy must == Nil,
Maybe if your indexing it with time it could be overflowing?


how can we deal with time problems?


2

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.


Oh thank you Shy !
It's ok, the problem is solved.
Your solution works.



[Please log in to post a comment]