Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Ticked_Off_Pixel on August 12, 2013, 08:10:05 PM

Title: Large Numbers - Doubt
Post by: Ticked_Off_Pixel on August 12, 2013, 08:10:05 PM
Hello everyone.

I have a variable (int) that stores the population size of a planet, but, when it reaches a little over 2 billion, the value turns to negative and gets all messed up.

I believe it's because an INT number can only go so high.

What can I do to get bigger numbers, like 10 billion or so?  :o

Thanks for your help.
Title: Re: Large Numbers - Doubt
Post by: Alex Chouls on August 12, 2013, 08:17:06 PM
What level of granularity do you need? Maybe the number could represent hundreds (1 = 100) then just add zeros to the string when you display the result...
Title: Re: Large Numbers - Doubt
Post by: Red on August 12, 2013, 09:43:26 PM
and to extend this if you need the finite... have the number be in stages... so, you take two ints, one is for the "millions" magnitude and one for below that.

So, if you have this many: 3,435,234,234,234,364

You take the billions as 3,435,234... and you take the rest as 234,234,364

how to fill them... take the int that represents below the billions... every time it reaches one billion, add one to the other int and set this one as 0 (essentially making a sort of "rolling over" effect.)

Same thing when you roll below 0 on the first int (the "millions" one) subtract one from the billions int and set this one to 999,999,999.

and how to display them (if you want to convert it to something the player can see) just take both values, convert to a string and use the "Build string" function to take those two values as strings and put them in a third value to use as the display.

I guess you could make this be a way of handling more than the int can do but not for calculations over the total amount there... so, if you wanted to make a calculation that needs the combined number, you'd be out of luck here because int's just aren't made to handle those kinds of numbers... but if it's just for a tally thing this might be what you're looking for.
Title: Re: Large Numbers - Doubt
Post by: Ticked_Off_Pixel on August 13, 2013, 07:34:19 AM
Thanks, guys!

Alex's idea should work better for me.

I need granularity, so i'll try to fake a variation for the numbers at the end of the string.

But it'd be great if we could use larger numbers more easily. It's an issue with Unity or Playmaker? Can it be fixed in the future?
Title: Re: Large Numbers - Doubt
Post by: Alex Chouls on August 13, 2013, 09:38:44 AM
It's a limit of the int data type used by Unity and Playmaker:
http://msdn.microsoft.com/en-us/library/system.int32.maxvalue.aspx

You could consider using a float and dropping the decimal places when displaying as text. You'll get larger numbers but you'll lose precision when the value gets very large...