JavaScript maximum value? How to make a failsafe for it?

Hi everyone,

I want to make a “total score” variable. This means adding every single point of score from the player’s first game to their millionth game, as long it’s more than zero.
This will basically be “total gameplay time” as my game Boxwindow counts 1 second = 1 score.

So, What is the maximum number variable value? Like how in Pac-Man for example the 8-bit integer limit is 256 and so the game ends/crashes at that level , because no code was made to avoid crashing after winning level 255.

I believe number variables in GDevelop are float and so the maximum number is 1.7976931348623157e+308 . (No idea how to read that, by the way.)
One can also reference this number by Number.MAX_VALUE in JavaScript.
(source: javascript.plainenglish.io by Casey Gibson )

So what I wanna ask is:

  1. How do I call this Number.MAX_VALUE in GDevelop event? Is it a function and would be like Number.MAX_VALUE() ?
  2. What is a good way to handle number overflow?
    I’m thinking to make a condition to check if variable maxScore + variable currentScore > Number.MaxValue().
  3. Does GDevelop/JavaScript break if I don’t do anything to prevent the number overflow?

Thanks in advance for your interest in this incredibly nerdy question!

The Clamp expression is your solution.

clamp(YourVariableForScore,MinimumScore,MaximumScore)

So
If “Score” = 25000
clamp(Variable(Score),0,20000) will return 20000.

Edit: And no, I don’t think there’s anyway to call the maximum number. As far as I know the maximum number in Javascript is 9007199254740991 (9 quadrillion).

2 Likes

What if you just start making up bull shit for the numbers? For example Kajillion, Palion, Silverion. Then say 100 000 000 = 1 Kajillion, 100 000 000 Kajillion = 1 Palion, etc.

I believe this is what games like Tap Titans do so you can continually to crazy damage that would go past Number.MAX_VALUE.

1 Like

Thanks a lot Silver-Streak and Eiklahc!

I think I’ll have:

  1. a counter variable to say how many times the Total Score goes over 9 quadrillion (close to the max value or something),
  2. reset Total Score to 0 when it goes over 9 quadrillion, and display something based on those two.
    A limit of 9 quadrillion * 9 quadrillion seems pretty impossible to reach, anyway.
    Thank you again for answering such a specific question :laughing: :heart:
2 Likes