playMaker

Author Topic: High precision numbers with PlayMaker  (Read 7331 times)

Sunny

  • Playmaker Newbie
  • *
  • Posts: 12
High precision numbers with PlayMaker
« on: December 13, 2017, 07:10:38 PM »
Hi! I want to store numbers greater than 2147483647 in PlayerPrefs or just need to Add/Subtract/Multiply/Divide.  But currently, its not possible, as you may already know the reason why!

I also got to know that there are other ways to do so, like double or implementing own custom class.

So I wanted to know the best possible option that I can use to get the result with Playmaker. Also, it would be great if I could change those big numbers to M, B, T etc...

I really wonder, how all those Idle Games serves us such huge numbers!!

Any suggestion or tips are very much appreciated! Thanks!!
« Last Edit: December 15, 2017, 11:31:52 PM by Sunny »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How can I store a number larger than 2147483647 in PlayerPrefs?
« Reply #1 on: December 14, 2017, 12:57:36 AM »
Hi,

 Can you clarify? I am not sure I follow all of what you said :)

you can always save your numbers as strings then you can save much bigger numbers this way.

 Bye,

 Jean

Sunny

  • Playmaker Newbie
  • *
  • Posts: 12
Re: How can I store a number larger than 2147483647 in PlayerPrefs?
« Reply #2 on: December 14, 2017, 01:55:01 PM »
Hi Jean!

Thank you very much for your quick response. And sorry for me not being clear in my previous post.

Actually I am creating an idle clicker game and everything is complete and ready to go. But the main problem now arises is the Big numbers! Everything is working good and fine until the total money reaches to 2147483647. And after that every calculation just STOPS!

In first I couldn't track down the problem, than later after checking each and every states, I realized the problem is with the Unity's limit to 2147483647 for Int numbers. And this has becomes a huge problem for me, I didn't knew about this limit before.

As soon the total money reaches 2147483647, the Int calculation gets stuck, and game stops responding in that fsm. I can no longer add any Int numbers to 2147483647 and thus the game freezes instant.

And yes, I could save the 2147483647 as strings in the PlayerPrefs. :D But again, when I get that string value from PlayerPrefs, it gets stuck in the string to int conversion state!  :'(

This is the problem I am getting, and also not to mention how easily and soon, the game's upgrade and hire manager amount goes to millions!! There are times when I need to add 1,000,000,000 per second to the total money! So you might see how easily the game will freeze and how big the problem is.

I googled about this, and got few interesting options to go with, like storing the numbers as double or using BigIntegar etc.

Also, there are few important places that have discussed this topic in detail!

https://forum.unity.com/threads/big-numbers.369443/
https://www.reddit.com/r/gamedev/comments/5u5fcp/how_do_you_approach_really_big_numbers_for/
https://gamedev.stackexchange.com/questions/114911/how-do-idle-games-handle-such-large-numbers

This was a good read though, but they didn't described how they saved their numbers  ;D :'(
http://blog.kongregate.com/the-math-of-idle-games-part-i/

So, I just needed to know which option might be best for me when using Playmaker, when my numbers gets unusally very high in the game.

Thanks and Regards!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How can I store a number larger than 2147483647 in PlayerPrefs?
« Reply #3 on: December 15, 2017, 08:35:32 AM »
Hi,

 I see, yes unfortunatly, the only way is use a regular code to work with Double variables.

have you tried to use floats instead? like 1.0 would be equal to 1 Billion and so you can make operations like that I would give this a go.

 also, just curious why you want to go in such high numbers? is that not unreadeable? I mean the difference between 1,000,000,000 and 1,000,000,000,000 isn't that obvious after all. I would considering bringing it down a notch so that it fits into regular ints.

 Bye,

 Jean


Bye,

 Jean

GonerGames

  • Junior Playmaker
  • **
  • Posts: 53
Re: How can I store a number larger than 2147483647 in PlayerPrefs?
« Reply #4 on: December 15, 2017, 09:34:20 AM »
You have your value set as INT. This has the largest value allowable of 2147483647.
Changing this to a float will allow 3.40E+38 = 34 with 37 zeros behind it.
Doubles (which are not natively supported in Playmaker or PlayerPrefs) will get you 1.7E+308 = 17 with 307 zeros behind it.

It is possible to use Doubles with Playmaker. You will need to use a script to store the Double value and then convert to string to save, load and display.

You need to save the string value into PlayerPrefs and then convert it back into a double.

quick example: (just to give an outline)

Code: [Select]
//set up variables
public double scoreCounter;
public string scoreDisplay;

//get double to string value every frame
void Update()
{
//use the scoreDisplay to show value in game - use get property to dump into FSM
scoreDisplay = DoubleToString(scoreCounter);
}

//Functions for converting Double to string or string to double - C format used for currency display
    private static string DoubleToString(double doubleValue)
    {
        return doubleValue.ToString("C");
    }

    private static double StringToDouble(string stringValue)
    {
        if (string.IsNullOrEmpty(stringValue))
            return 0d;

        return double.Parse(stringValue);
    }


EDIT: Buy EasySave 2 from the asset store. This way you can keep the string in Playmaker Globals to save and load easily.
EasySave method:
FSM to save all global variables on exit or pause
FSM to load global variables then a call method to pass the StringToDouble function.
So much easier and secure than playerprefs. (Personal Opinion)
« Last Edit: December 15, 2017, 09:40:49 AM by GonerGames »

Sunny

  • Playmaker Newbie
  • *
  • Posts: 12
Re: How can I store a number larger than 2147483647 in PlayerPrefs?
« Reply #5 on: December 15, 2017, 10:55:11 PM »
Hi,

 I see, yes unfortunatly, the only way is use a regular code to work with Double variables.

have you tried to use floats instead? like 1.0 would be equal to 1 Billion and so you can make operations like that I would give this a go.

 also, just curious why you want to go in such high numbers? is that not unreadeable? I mean the difference between 1,000,000,000 and 1,000,000,000,000 isn't that obvious after all. I would considering bringing it down a notch so that it fits into regular ints.

 Bye,

 Jean


Bye,

 Jean

Hi!

Thank you for your reply. The Float is a great go!

But the game really requires numbers with high precision. And if I go with float, I lose many values when it gets big. Also, the numbers are very small in the beginning but as soon as the players gets to 20+ level (approx 5+ hours of gameplay) the amount reaches to millions. And as you can see, almost every idle game now reaches beyond 1,000,000,000,000,000,000 in just few hours of gameplay! and, the game's entire programming too has been setup up to go beyond those big numbers later in the game!! (without me knowing the int limit earlier!  :'( )

There is one other game I could use your float suggestion to, as that doesn't require high precision!

Also, please have a look at this link,

https://answers.unity.com/questions/17858/high-precision-numbers.html

So, Is the long, uint, ulong, double or decimal officially supported in Playmaker? If yes, than I could go easily with them, or else I might have to find some other way like you suggested to use a regular code to work with double variables.

Thanks!

Sunny

  • Playmaker Newbie
  • *
  • Posts: 12
Re: How can I store a number larger than 2147483647 in PlayerPrefs?
« Reply #6 on: December 15, 2017, 11:14:55 PM »
You have your value set as INT. This has the largest value allowable of 2147483647.
Changing this to a float will allow 3.40E+38 = 34 with 37 zeros behind it.
Doubles (which are not natively supported in Playmaker or PlayerPrefs) will get you 1.7E+308 = 17 with 307 zeros behind it.

It is possible to use Doubles with Playmaker. You will need to use a script to store the Double value and then convert to string to save, load and display.

You need to save the string value into PlayerPrefs and then convert it back into a double.

quick example: (just to give an outline)

Code: [Select]
//set up variables
public double scoreCounter;
public string scoreDisplay;

//get double to string value every frame
void Update()
{
//use the scoreDisplay to show value in game - use get property to dump into FSM
scoreDisplay = DoubleToString(scoreCounter);
}

//Functions for converting Double to string or string to double - C format used for currency display
    private static string DoubleToString(double doubleValue)
    {
        return doubleValue.ToString("C");
    }

    private static double StringToDouble(string stringValue)
    {
        if (string.IsNullOrEmpty(stringValue))
            return 0d;

        return double.Parse(stringValue);
    }


EDIT: Buy EasySave 2 from the asset store. This way you can keep the string in Playmaker Globals to save and load easily.
EasySave method:
FSM to save all global variables on exit or pause
FSM to load global variables then a call method to pass the StringToDouble function.
So much easier and secure than playerprefs. (Personal Opinion)

Hi GonerGames!

Thank you for your reply! The floats are not highly accurate, so I am not able to use that in the game. But the use of double, is really a way to go! And I have also heard from many people to use double for big numbers, but again, there are limits to this too, like its not natively supported in Playmaker and PlayerPrefs. So, if this is the only option I can get big values with high precision, than I think I will have to hire someone to script it.

Also, I have two games, thats Idle clicker, one requires high precision numbers, other doesn't. In the first, I can use float with the suffix Million to 1, as Jean suggested. And on other one I will have to use double, as the last resort.

And, also I am interested to know, why the double is not officially supported in the Playmaker! But long can hold value up to 9223372036854775807, is this supported in Playmaker?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: High precision numbers with PlayMaker
« Reply #7 on: December 18, 2017, 02:33:18 AM »
Hi,

 long is not supported too, only regular Ints.

 using doubles and long is very advanced and so in this case I think it's been ruled that it was not necessary for PlayMaker, as it really complexify the situation for everyday usages, and will confuse users more than help.


 Bye,

 Jean

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: High precision numbers with PlayMaker
« Reply #8 on: December 18, 2017, 05:26:18 AM »
Hi.
I must say that i also had issues when i made an idle game, but i can remember that i did have a workaround for it.
I will try to lookup the game when i get back home.

But i do think long / double should be supported,
i recently made a calculator sample and had also problems with the limitations from a float.

Maybe it can be supported and place the actions in a package on the Ecosystem and not in the standard action list to prevent confusion for new users?

i can also remember someone having issues also with coordinate not being accurate enough due to the float limitations

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: High precision numbers with PlayMaker
« Reply #9 on: December 18, 2017, 11:19:17 AM »
Hi,

 unfortunatly, it can only be supported internally with a new FsmLong and/Or FsmDouble with all the related actions to work with it.

 or, another solution would be an option inside FsmInt to turn it into a double or long but some actions my need updating to take care of these options.

 Bye,

 Jean

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: High precision numbers with PlayMaker
« Reply #10 on: December 18, 2017, 05:12:53 PM »
Hi,
I think 1st option would be best, i would be willing to make actions for them if it would be supported.

And as a said, maybe it is best to have them in a package on the Ecosystem instead of including to the standard included actions :)

Sunny

  • Playmaker Newbie
  • *
  • Posts: 12
Re: High precision numbers with PlayMaker
« Reply #11 on: January 02, 2018, 09:41:53 PM »
Hi,
I think 1st option would be best, i would be willing to make actions for them if it would be supported.

And as a said, maybe it is best to have them in a package on the Ecosystem instead of including to the standard included actions :)

Hi djaydino!

Thank you so much for your reply and showing your interest in this topic. I also wish to see those actions in the Ecosystem soon. There are lots of uses of those big numbers, so I just hope those actions can be added to the Ecosystem as soon as possible.

And in my case, I have decided to end the game as soon as the player strikes the highest Int value for now.

Thanks again!!  :)

Sunny

  • Playmaker Newbie
  • *
  • Posts: 12
Re: High precision numbers with PlayMaker
« Reply #12 on: January 02, 2018, 10:01:29 PM »
Hi,

 unfortunatly, it can only be supported internally with a new FsmLong and/Or FsmDouble with all the related actions to work with it.

 or, another solution would be an option inside FsmInt to turn it into a double or long but some actions my need updating to take care of these options.

 Bye,

 Jean

I will wait for those actions to be added in the Ecosystem or in the standard package, whichever ways works best. And if its added, lots of people will benefit from it and appreciate it too.

And also, please check the screenshot of my game below, of which this topic is about. The ALL TIME scores have reached its boundary whereas, TODAY's scores, as you can see, still have potential to reach the highest int value currently supported by my game. And player's are complaining about the very short game. So, this has become the biggest problem for my game now. Which has to be fixed soon either through the Playmaker official actions or custom actions.

Thanks you very much Jean!!  ;)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: High precision numbers with PlayMaker
« Reply #13 on: January 05, 2018, 06:15:38 AM »
Hi,

 ok, there is a miunderstanding here, the number I see in your screenshots are totally fine as regular ints... I am not sure you are going in the right directions with doubles.

int range in c#: -2,147,483,648 to 2,147,483,647

2 billion is fine right for scoring no? I strongly advice you cut down on the scale of your score so that it fits 2 billion, I don't think it make sense to have such large numbers for a game score.


Bye,

 Jean

GonerGames

  • Junior Playmaker
  • **
  • Posts: 53
Re: High precision numbers with PlayMaker
« Reply #14 on: January 05, 2018, 10:06:02 AM »
Moving to a float would also get you a higher value allowable.
int = 2.1e+09 or 2,100,000,000
float= 3.4e+38 or 340,000,000,000,000,000,000,000,000,000,000,000,000

Converting float to string with a format 0 will remove the decimal places from showing. You can also format the string to allow the number to more human readable.

eg. 3 Billion -> 300 billion -> 3 trillion etc. instead of 3,000,000,000 -> 300,000,000,000 -> 3,000,000,000,000

If you are tracking scores above a trillion I, personally, wouldn't be too concerned that float may not give the precision you need as you are getting into massive numbers that start to lose meaning. Not a lot of people even know what comes after a Trillion  :)

Thanks