[Help] Comma System for Numbers. 10000 shows up in text as 10,000

0 favourites
  • 2 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • This is for a money/buying system in my game

    I need help with this....

    Problem:

    So I'm having a issue I want to turn a number variable like 10000 to display on set text. 10,000 or every 999 the next number over will add a comma.

    Found a Solution (Sort Of):

    I tried tons of different ways then came across this old forum post.

    construct.net/en/forum/construct-2/how-do-i-18/string-numbers-commas-127611

    Anyway they used Events and Actions like this to create something that sort of works.

    Problem is it adds commas before needed. 999 ends up being ,999

    System: Every tick

    System: For "" from 0 to tokencount(str(PocketCASH), "")%3

    -> PocketCASH: Set text to left(str(PocketCASH), LoopIndex)

    ----+ System: tokencount(str(PocketCASH), "") > 1 and len(str(PocketCASH)) > 3

    ----+ System: For "put" from floor(tokencount(str(PocketCASH), "")÷3) to 1

    -----> PocketCASH: Append ","&left(right(str(PocketCASH), LoopIndex×3), 3)

    --------+ System: tokenat(Text.Text, 0, "") = ","

    ---------> PocketCASH: Set text to right(PocketCASH.Text, tokencount(PocketCASH.Text, "")-1)

    My attempt at solving this:

    I tried adding a condition

    ----+ System: len(str(PocketCASH)) > 3

    However when I add this, now all the Money. Disappears whenever I press a button to purchase something in my game. But without this condition the purchasing works fine and the text updates, except with the annoying ,999 Comma before needed.

    Can someone help me?

    Original Question:

    Anyone know how to make a Text_SET, that is a Global variable, have commas in the Text. Like the variable is 10000 so the text displays 10000 now how would I get the text to display 10,000 instead?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Here's a copy of the code I used to convert numbers to decimals. Sorry it's from a phone screen shot, I'm not at the computer.

    Long code for the return value function so you don't have to type it manually:

    right(left(zeropad(round(Function.Param(0)),maxdigits),maxdigits-9),clamp(len(str(round(Function.Param(0))))-9,0,3)) &(len(str(round(Function.Param(0)))) > 9 ? seperator : "") &right(left(zeropad(round(Function.Param(0)),maxdigits),maxdigits-6),clamp(len(str(round(Function.Param(0))))-6,0,3)) &(len(str(round(Function.Param(0)))) > 6 ? seperator : "") & right(left(zeropad(round(Function.Param(0)),maxdigits),maxdigits-3),clamp(len(str(round(Function.Param(0))))-3,0,3)) &(len(str(round(Function.Param(0)))) > 3 ? seperator : "") &right(mid(zeropad(round(Function.Param(0)*10),maxdigits) ,maxdigits-4,3),clamp(len(str(round(Function.Param(0))))-0,0,3))

    Then you need to set the text to the global variable of your numbers, e.g coins or hearts, but with the function and the variable instead of just the variable like this

    Hope this helps, if you need desktop screen shots or an example .c3p file let me know and I'll sort it out tomorrow when I'm on the computer

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