I have been slowly building a game where the part of the goal is to make as much money as you can, I am not 100% sure players of the game would ever get to 1,000,000,000 however if they did I’d like the game to not to go in to panic. At the moment, when I go past 1 billion the numbers go in to -1 and then just goes crazy…this has something to do with bits.
Is there a way of allowing a number to continue past 1 billion? I have thought about “fudging” the numbers by having separate numbers for everything up to a billion and then another variable for everything over a billion. However I haven’t found a satisfactory way of doing this. As with most games money is displayed on the HUD at all times and is laid out in the “best” way possible for space, ETC. Having to shove in more text for “if” a player goes past 1 billion doesn’t work. Plus the player’s money is going up and down every month (depending on their success) which means making sure I add the right money past a billion, then if they go under through spending to go back down from 1 bill.
I’m not seeing a way to do it but I assume other people must want to store numbers past 1billion if they are doing a game with money, population, ETC.
Any mathematical help would be greatly appreciated.
You didn’t mention what the type of the variable your using is, I’m going to presume that it is a integer. An integer should have no problems with 1 billion. As integers in Blueprints are signed values, giving the following Min/Max values.
(if you are curious, this is called “twos complement notation”, because the negative value is capable of representing 1 number larger (although it is negative) than the positive number)
So I doubt that 1 billion is the culprit of making things go crazy. Assuming that you are using the integer data type. As you are representing money, I would highly suggest that you do use integers to represent the quantity. Trying to do this with floats is possible, but you are subject to rounding errors, if you allow the representation of the money to include any value in the exponent (i.e. 123.45 where “45” would be the exponent). Or if you wanted to allow the afore mentioned “45”, then you would probably always want to do a truncate after each math operation on the values.
For most games, the range of integers is generally sufficient. In that you need to determine, how fast people can make money in your game, and then determine how many years it would take them to achieve that, using the maximum speed that they can acquire money.
Hope this helps,
Thanks for the reply, I am using an integer for the variable. I am not certain it is 1billion exact that causes the issue. I added a key press function that adds 1billion to the money amount with each press. I was doing this really just to see how that amounts of characters affected the HUD space. However when I pressed the button a few times the number just jumped all over the place, from -1 to 14,000,000 to -274,000,000, ETC.
The game I am making at the moment is a business management sim, during the opening part of the game this kind of figure will be out of reach, but in the latter/final stages of the game I would imagine players could be going up and down in billions every quarter. I would expect players to be dealing in the 10’s if not 100’s of billions later on in the game cycle. The idea of the business is to make money and constantly expand in order to make more money. So having a limit on that could be an issue.
I just wondered if there were other people doing games where a variable had to store N billions as a constant flow (up/down) and how they track that flow if you can’t have over 2147483647.
When you go into the blueprint editor, you can see what is happening to the variable, when say, you type in 3 billion for the default value, the editor is resetting it to the Maximum Negative value. This is ocurring because the maximum positive value has been exceeded, by flipping on the high order bit of the 32 bit value. So now that you know the maximum value, you can either try to stay under that value.
Or, you can try to deal with it, and create a 64 bit value, and attempt to work with that. I cannot think of a way to easily do this in blueprints. You will be much better off, doing this kind of work, in C++ as a plugin, and setting up blueprint entry points into the plugin, for the arithmetic that you need. Probably by creating a structure, to represent the value, as you will need to keep the value as C++ needs it (so your not converting back and forth all the time), and as the blueprint needs it (i.e. 2 integers).
Hope, this helps,
Thanks, I was really hoping to avoid any plugins and certainly doing any C++ work. It’s a shame there isn’t a way to do the same thing in Blueprints, seems like something of a limitation for a number of concepts, especially if you were dealing in currency like the old Italian Lira where 50,000 was their lowest note (it may not have been it has ben a while)
Anyway thanks for your time and help, my quest continues! I may just have to re-think the currency in such a way where players don’t/wont ever require that kind of cash.