Puzzling behavior with IntValues

I have a game in which I use IntValues to keep track of player’s magic. At a certain point, that IntValue goes negative. I’ve tried to find the cause for this but to no avail; what do I do here?

IntValue = game.Players.Arcerion.Magic
IntValue.Value = IntValue.Value + 1

How high does magic go? It might overflow at 9,223,372,036,854,775,807, the highest 64 bit signed int.

If that’s the max number and after that players go negative then that’s as high as it goes. Since this game is a simulator, you gain infinite numbers.

You’ll have to use a BigNum implementation. See: How do you handle numbers larger than the max?

I’m not an expert when it comes to simulators, but I question the need for arbitrary precision. If your players’ magic levels most likely will not surpass 10^300, a NumberValue could do the job. (Personally, I think any simulator with scores exceeding this number probably needs to be re-designed.) However, NumberValues are double-precision floating point — in other words, you only have around 16 significant figures.

Depending on what kind of mechanics your game offers, arbitrary precision might be necessary, but otherwise it’s often better to avoid importing code libraries if they’re not strictly necessary.

1 Like