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


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

P#84877 2020-11-30 21:11 ( Edited 2020-11-30 21:13)

:: merwok

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

P#84887 2020-12-01 02:17

Yes the complete code error is :

runtime error line 35 tab 6
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)

P#84907 2020-12-01 18:14

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

P#84908 2020-12-01 18:48

how can we deal with time problems?

P#84948 2020-12-02 18:16
:: shy

Here's the cause of the bug: in your couleur_plus() function, you have this code:

      if (test==1) niv+=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.

P#85941 2020-12-30 19:44

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

P#85969 2020-12-31 12:59

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2021-01-18 20:56 | 0.021s | 4194k | Q:39