Why is this code not functioning properly? [Solved]

Yerghaiz

• Posts: 17
Hi everyone! So, here's the deal.  I am currently working on an incremental game, and everything works fine, until I hit the Billions of dollars mark.  Then, all of a sudden, this bit of code...

...ceases to function properly, only subtracting about 1.4 mil from the money total, while properly adding the XP to Character XP Attribute.

Now, after some experimentation, I have hit a brick wall with how to fix this issue.  In the below screenshot, I have highlighted 3 numbers.   The first is a scene attribute, displaying a pretty large number.  The second is a game attribute, displaying an even larger number.  The third (and this is where I am having my issue), is a full display of the Money Attribute, which counts up to twenty million, goes negative, counts up to 20 million again, repeats indefinitely.

So, I am wondering what, if anything, can be done about this?  Any feedback or help would be greatly appreciated, and I will be more than happy to supply any other information necessary to get this fixed.  Thanks in advance.

« Last Edit: January 11, 2015, 11:38:20 pm by Yerghaiz »

Yerghaiz

• Posts: 17
Small, partial progress on this.  I have determined that the code used to keep the display down to 2 decimal places...

...is what is causing the negative number issue.  That however, raises the question of why it is wrapping around negative, only when this formula is used, and only partially answers the original question of why it is only subtracting 1.4 Million from money when the button is pressed.

Yerghaiz

• Posts: 17
So, I have determined that the round code, whether it is floor, ceiling, or round, causes the negative integer wraparound, and was also preventing the code from subtracting more than approx 1.4 Mil per click of the button.  So, now the question arises, what can be done to keep the math accuracy of my equation, without using the rounding function.  Technically speaking, this code should, unless the amount of money is an exact multiple of 10, always leave a positive integer remainder.  Any help with this would be great.  Thanks!

letmethink

• Posts: 2545
If you use very big numbers I would suggest creating a list system for storing numbers and code addition and subtraction for a number with its digits stored in a list.
~Letmethink

ohlin

• Posts: 71
Seems to me that you're trying to make a "Make it rain" type of game, where you accumulate cash over time? Anyway, you can do it easier this way

1.000 = 1 K
1.000.000 = 1 M
1.000.000.000 = 1 B
1.000.000.000.000 = 1 T
1.000.000.000.000.000.000 = 1 Quint
1.000.000.000.000.000.000.000 = 1 Sext
..................................... (http://en.wikipedia.org/wiki/Long_and_short_scales) for more

Then it is easy. Just convert when it gets bigger than 1000 to 1, then up the scale to the next one (make a list for it maybe).
If it gets smaller than 1, turn the scale down. Easy.

Yerghaiz

• Posts: 17
I get what you guys are saying, and the large numbers aren't inherently the issue, so I apologize for my lack of clarity.  What I needed to know is why is the round function causing my numbers to be capped at a much lower number than the attribute itself can store?

Though I suppose I can just use a comparative, using the long/short numbers system to do the math using scientific notation for my cost equation.  Just seems like a lot of extra work when the attributes themselves appear to be able to handle numbers well beyond what the round function is allowing me to work with.  I'm going to leave this open for now, if no other solutions are presented in the next 24 hours, I'll call it solved.  Thanks ohlin and letmethink.

letmethink

• Posts: 2545
Basically, most computer programs use approximated maths where theu don't work everything out perfectly. If numbers get too high they stutter. I remember reading about this somewhere, but I'm not sure what it was called.
~Letmethink