Integers overflowing in the low billions?

Galdon2004

  • *
  • Posts: 275
Hello, I am working on an incremental game at the moment, and am hitting a problem with large integers; I had asked about them before and was told that the point at which integers should overflow is about 10^308; but instead I am getting a result that integers are consistently overflowing into negative values at about 2.2-2.3 billion.

This seems like a remarkably low number to overflow on, especially for an incremental game. Is there anything I can do to overcome this issue; or is this limit pretty much hard coded into the system?

Edit: Something else I do notice is that it only seems to do this when math is involved with the number; if I set a number directly to 2.3 billion and ask the game to display it, it works. When one of my formulas creates a number at that value, it overflows. I've attached the math formula which is causing the issue.

« Last Edit: October 29, 2018, 10:34:02 am by Galdon2004 »

rob1221

  • *
  • Posts: 9461
That 10^308 value refers to floats, not ints, which have a much lower max value which you already ran into.  If you use floats (normal numbers in Stencyl without rounding) then you'll need to format those numbers when displaying them, but for an incremental game you should already be doing some formatting.

Galdon2004

  • *
  • Posts: 275
Yeah, the problem I have with not rounding is that for some reason they have this weird tendency to do stupid things like

100-5 = 95.00000000000000000000000000000000000001

which just kills my display. Is there any way to avoid that problem while not using rounding?

rob1221

  • *
  • Posts: 9461
Incremental games don't typically display the raw number and instead use a text format that includes the first 1-4 digits and then either scientific notation or some letter combination.

Galdon2004

  • *
  • Posts: 275
Is there a good way to just grab the first four digits of an integer? I've been doing it the long way like:

If (Variable) < 1,000
  Set (display) to Round(Variable)
  Set (display letter) to (blank)
If (Variable) < 1,000,000
  Set (display) to (Variable/1000)
  Set (display) to Round((Variablex100) / 100)
  Set (display letter) to K
(repeat for million, billions, and trillions)

Also, to be clear, the overflow would only happen when using a Round () block? Or is there a different attribute type I need to use?

rob1221

  • *
  • Posts: 9461
There's a block to get a part of text that you could use.  You could also split the text using a period as a separator.

A number attribute is fine as long as you're not setting it to a rounded value.  There might be other blocks that converts to int but I don't remember.

Galdon2004

  • *
  • Posts: 275
I'm looking in my code and I don't have anywhere that the number that is overflowing gets "set" as a rounded number. Is it also set to an integer when it is used in a math formula which uses a rounded value?

rob1221

  • *
  • Posts: 9461
I forgot that game attributes are Dynamic, not Float, so if you're doing integer math then the compiler might be assuming Int.

Galdon2004

  • *
  • Posts: 275
Ah ok. I will try to see if I can figure out a way to use the number variables in my math indirectly and see if that works then...