# Not a Number error

I am developping a little game with GameMaker Studio.

I am sorry if this is a silly question, but I keep getting NaN as a result of this equation :

    Team_Joueur.PVsRandom[Setup_Battle.PokemonAleatoire] -= (( 2 * Team_Joueur.Niveau[0] + 10) / 250 * (Team_Joueur.Attaque[0] *
(ModificateursSimples(Team_Joueur.Modificateurs[0, 0]) / 100)) / (Team_Joueur.DefenseRandom[Setup_Battle.PokemonAleatoire] *
(ModificateursSimples(Team_Joueur.ModificateursRandom[Setup_Battle.PokemonAleatoire, 1]) / 100)) * Team_Joueur.Puissance[0, Position] + 2)
* (STAB * Coup_Critique * round(random_range(0.85, 1.01)));


Here is the original equation :

And here is the equation with simpler variables' name :

HP[Pokemon] -= (( 2 * Level[0] + 10) / 250 * (Attack[0] *
(Modif(Modificators[0, 0]) / 100)) / DefenceOpponent[Opponent] *
(Modif(ModificatorsOpponent[Opponent, 1]) / 100)) * Power[0, Attack] + 2)
* (STAB * Critical * round(random_range(0.85, 1.01)));


I tried each argument and they are all numbers, not very large, and drawing the equation gave me the result...

draw_text(32, 224, string(Team_Joueur.PVsRandom[Setup_Battle.PokemonAleatoire] - (( 2 * Team_Joueur.Niveau[0] + 10) / 250 * (Team_Joueur.Attaque[0] *
(ModificateursSimples(Team_Joueur.Modificateurs[0, 0]) / 100)) / (Team_Joueur.DefenseRandom[Setup_Battle.PokemonAleatoire] *
(ModificateursSimples(Team_Joueur.ModificateursRandom[Setup_Battle.PokemonAleatoire, 1]) / 100)) * Team_Joueur.Puissance[0, 0] + 2)));


PS : The 'Modif' function returns a number based on another one.

I am deeply sorry for my code, I know it's messy.

• It might be easier if you break up your larger equation into a few smaller pieces and store them in temporary variables. For example, store (2 * level[0] +10) / 250 as its own variable, attack / defense as another, etc. Then run the full equation. Throwing everything into one equation on one line can make debugging problems like these very difficult. Chances are good that if you break it up you'll be able to narrow down which part of the equation is causing your error. Commented Jan 13, 2017 at 0:05
• Thank you ! I got the wrong part, but can't understand why it is wrong :/ Team_Joueur.DefenseRandom[Setup_Battle.PokemonAleatoire] * (ModificateursSimples(Team_Joueur.ModificateursRandom[Setup_Battle.PokemonAleatoire, 1]) / 100)) It's the part that divides the attack Commented Jan 13, 2017 at 0:29
• Try breaking it up even further. Is it the multiplication? The division? Maybe check that the values that you're getting out of those arrays are what you expect them to be. Not sure if Game Maker has a debugger that you can use to step through the code. If not you can always just print out the values. Commented Jan 13, 2017 at 0:33
• I tried few things, and here is what I found : ModificateursSimples(Team_Joueur.ModificateursRandom[Setup_Battle.PokemonAleatoire, 1]) / 100; is making the NaN. But ! When I print it, it's a number, and the correct one. Commented Jan 13, 2017 at 0:42
• BTW, round(random_range(0.85, 1.01)) always will return 1 Commented Jan 13, 2017 at 4:38

Ok, the problem was in my function ModificateursSimples : I was returning a value in a switch, thus never reading the line break;, and when coming back to that function, the switch was never clearly closed before, thus buging.