- Home /
Clicker game amount reaches max int limit
I want to make a game sort of like cookie clicker but I have a question, how do they store numbers that are bigger than an int or a long. How can you display a number from 1 - 999 and the display a multiplyer such as millions billions, trillions, or octillion. For example 1 000 000 turns into 1 million or 32 000 000 000 turns into 32 billion.
Answer by Eno-Khaon · Nov 12, 2018 at 07:21 PM
I offered an idea on how to handle this a few months back. Because the numbers become so large in that game genre, my suggestion was to create a class/struct which would effectively ignore numbers that are drastically different from each other and stick with the heavily optimized 32-bit math libraries.
In regard to showing long names (alternate link), you could take this class/struct and overload its ToString() function to pull or construct a name from a list based on the number of digits, as well as using that number of digits to determine whether to show 1, 2, or 3 numbers before the name.
As a rough, simplified example of this, using a value and a factor of 10 to multiply it by:
// Excerpt from ToString()
// Subtract 1 since "thousand" starts at 3 zeroes
// Otherwise, don't subtract 1 and leave element 0 blank
int element = (factor / 3) - 1;
float printedValue;
string printedString;
if(element < longNameArray.Length)
{
printedValue = value * Mathf.Pow(10.0f, factor % 3);
printedString = string.Format("{0} {1}", printedValue.ToString("F3"), longNameArray[element]);
}
else// if(number is larger than the list of names)
{
// Create the string in a format more like
// 5.023e32056
}
return printedString;
Edit: Fixed formatting
Thanks for your detailed answer even though I don't really get it lol.
Sorry to say, I haven't gotten around to writing a math library set for this for myself yet, so I don't have any complete examples to provide.
I'm happy to at least point you in the right direction when I'm able, though.
It’s okay, I figured it out myself. Thanks for trying though.
Answer by Vega4Life · Nov 12, 2018 at 06:37 PM
You should be using decimal, float, or double. A lot of those clicker games are only showing a few numbers anyways, once they get over a million, so precision isn't super important. Thus you could probably get away with using float or a double.
I have also seen a few games that upon reaching max limit of these values, they just show infinity - which is an interesting way of dealing with the problem.
Answer by Luischo · Nov 13, 2018 at 06:26 PM
As @Vega4Life say, "precision inst important on those games, so, your int variable will store how many of some unity you will show. Let me explain, in a progresion you will show:
1 to 999
1 K to 999 K (not 999000)
1 "bazillion"
1 and the like
So, you need 2 variables, 1 for the number part and the other for the string.
Your answer
Follow this Question
Related Questions
Cannot convert 'callable(int) as float' to 'float'. 1 Answer
Object to int 1 Answer
c# convert int to string 2 Answers
Having a GUI text as a int 3 Answers