Add commas into score/number

0 favourites
From the Asset Store
Add SubRip (SRT) subtitles to your videos in Construct 3
  • I'm using Spritefonts for my score display and wanted to add commas into my score, like 12,454,343 or 1,234 etc.

    I've searched online and found a thread that does focus on this -

    But the example there is not working for me, maybe i'm doing it wrong. I'm using the scoring from the Autorunner Template but i can't seem to implement the example into the scoring, either nothing happens or i get issues such as crazy numbers appearing with decimal points.

    Does anyone have a suggestions on how i can add commas into my scoring?

    Thanks

  • Thanks for the capx but i have to say that is quite confusing for me, I don't know where to begin Does it usually take this amount of events to add commas to a score?

    Is it possible to implement this into the Autorunner Template scoring? If so, what exactly do i do? If someone can provide a capx of the commas being added to the Autorunner Template scoring then that would be helpful.

  • add function object

    add variables to the game

    copy function

    paste function

    replace the text statement function.call("function name",numberToDisplay)

    tada

  • You can also do it in one line using RegexReplace expression (aka, voodoo magic).

    RegexReplace(scoreVar, "\d(?=(\d{3})+$)", "g", "$&,")[/code:3gom10ma]
  • Those are two excellent answers.

  • Thank you for your responses, it's extremely helpful and appriciate you guys taking time out to help out.

  • I'm a beginner here and I too was looking at how to insert commas into numbers. Thanks trultz for the detailed guide into doing this.

    I'm curious to Magistross & ggibson1 method of doing this. Could you guys go into a bit more detail on how to use this expression please? I've tried inputting this into my score via functions but its not worked for me as nothing happens.

    I haven't found many topics that talk about RegexReplace so my knowledge on the matter isn't great, which is probably why it hasn't worked for me.

    Thanks.

  • well i think i found the problem

  • I checked your CAPX. I noticed the number you want to format has a floating point. My Regex assume you don't. The "FormatCurrency" Regex assume there is a floating point. So you might have to combine both in a function and use the appropriate Regex. Be sure to pass the value as a string to the regex, otherwise it might behave strangely. You can do that by appending an empty string to the variable (implicit conversion), or using the str() function (explicit conversion).

    Here's the modified CAPX.

    tomhaiger You might want to read a bit on "regular expressions" in general, especially the Javascript variant, which lacks the lookbehind functionnalities. It's quite a powerful feature for matching and replacing strings.

  • i edited my previous post, after adding int(number) it worked fine, and for the currency int(number*100)/100. Thanks for the tips, much smaller code than i was using.

  • I'm a beginner here and I too was looking at how to insert commas into numbers. Thanks trultz for the detailed guide into doing this.

    I'm curious to Magistross & ggibson1 method of doing this. Could you guys go into a bit more detail on how to use this expression please? I've tried inputting this into my score via functions but its not worked for me as nothing happens.

    I haven't found many topics that talk about RegexReplace so my knowledge on the matter isn't great, which is probably why it hasn't worked for me.

    Thanks.

    [attachment=0:3102jdac][/attachment:3102jdac]

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I've got this working with my scores during gameplay so thanks for that but I've got an issue trying to get this to work with my webstorage.

    Basically when i try to input this into my webstorage event which saves and displays highscores, it works the very first time after reseting webstorage value but after that the score doesn't update regardless if the score has been beaten until i reset the webstorage value again.

    I've provided a screenshot of what i've done, i hope this is enough to go by

    Sorry if i missed out anything out, hopefully someone can help.

  • I've got this working with my scores during gameplay so thanks for that but I've got an issue trying to get this to work with my webstorage.

    Sorry if i missed out anything out, hopefully someone can help.

    What I normally do to quickly find the bug in my code is use a Browser.Log and write out the variable in question or the return value of a function...etc. until I see what is going wrong.

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