How do I format numbers for an economy game?

0 favourites
  • 5 posts
From the Asset Store
The ultimate voice pack filled with 1,536 files of .......wav and mp3 of individual numbers, letters, and words (that go
  • Working on an economy/idle game and I can't figure out the number formatting. I'm trying to get it to display large numbers in a more readable fashion. Currently I am using a janky comparison to determine the number group and append it to the number. Which as janky as it is, pictured below, it does work. However, I can't seem to get the number part to format correctly without just brute forcing it.

    I would like the game to be able to format the numbers like below without me having to manually enter in comparisons to see what the value is and how it should be formatted for each number group.

    100 - Hundreds

    1000 - Thousands

    10.0 - Ten Thousands

    100.0 - Hundred Thousand

    1.0 - Million

    10.0 - Ten Million

    100.0 - Hundred Million

    Etc

    Any ideas?

    Tagged:

  • So I wasn't able to find an elegant way to program this so that I wouldn't have to brute force it. And although the way I have it set now works, it will fail as the number will eventually get to large to store in a variable properly. I figure if anyone gets to that point in the game though, there may be interest to create it properly with actual code instead of Construct. Anyway, for folks looking for something similar see the code below.

    Money variable stores the actual value of funds the player has. The Display Money variable is used to manipulate that value in a visually appealing way without messing with the actual value.

  • Generally speaking, for absurdly large numbers such as in idle games you'll want to store the number as separate pieces. There are several ways to do this. For starters, rather than using a series of if/then statements, you should be able to cover n number of digits with a single function, by getting the length of your number with len(number) or just getting the relevant portion of the number with left(number, relevantdigits). There should be a lot of posts about how this is applied to break up numbers. You'll always have to define labels/suffixes individually though. For a cleaner but more complicated system, you could store your suffixes in an array.

    To handle mega large numbers, one way is to push values into array cells. The most straightforward way would be for each digit to have it's own cell. The width of the array would correlate to the number of digits in the number, and each digit could be represented by multiplying itself with 10^xindex.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • It's by no means my best tutorial, but this has a couple of clicker/idle game project files in there which uses a mathematical expression and a dictionary to do the numerical display. I haven't watched the whole of either video, but I think there might be a demonstration of how I did it. (It's been forever since I created this.)

  • Check out this thread. https://www.construct.net/en/forum/construct-3/general-discussion-7/format-number-currency-146104

    It has 2 examples, one for formatting eg 10,000,000, and one for adding denotations eg 10m, 10k etc.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)