Insert commas in score

Get help using Construct 2

Post » Thu Feb 27, 2014 1:28 pm

I'm using a spritefont for a score readout. I just want to insert commas in the score, like 12,000,000, or 1,000, etc.

Anyway, I found this example (not for C2):

http://gmc.yoyogames.com/index.php?showtopic=586659

Problem is...well, all the spritefont object has is 'append text', but what I want to do is, er (googling...) prepend, because otherwise I don't know where to put the first comma.

Or...maybe I'm confused... :?

...nah...

...any ideas? :mrgreen:
Don't lose your work. Backup your game with Dropbox.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,202

Post » Thu Feb 27, 2014 1:37 pm

Set text to ---> Variable&"."&Variable
B
17
S
4
G
1
Posts: 105
Reputation: 1,874

Post » Thu Feb 27, 2014 1:46 pm

Er, no, maybe I should have been clearer: I'm trying to insert commas dynamically. Like, if the score is 12000, I have an event which takes that, turns it into '12,000' and sets the spritefont to that (121004 becomes 121,004 etc).

Thanks anyway though. :)
Don't lose your work. Backup your game with Dropbox.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,202

Post » Thu Feb 27, 2014 1:53 pm

Try this
You do not have the required permissions to view the files attached to this post.
Last edited by DUTOIT on Thu Feb 27, 2014 2:11 pm, edited 2 times in total.
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,728

Post » Thu Feb 27, 2014 1:59 pm

Ah, yes, that's perfect! Well, except for the decimals...but I can probably get rid of them.

Much simpler than what I was trying...plus, it works.

Thanks @DUTOIT :D
Don't lose your work. Backup your game with Dropbox.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,202

Post » Thu Feb 27, 2014 2:01 pm

@TiAm, new file attached above - last one didn't show 1000000 correctly due to rounding error....

Credit goes to @R0J0hound - wish I could find his orginal thread on this.

And attached without the decimal
You do not have the required permissions to view the files attached to this post.
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,728

Post » Thu Feb 27, 2014 2:17 pm

@DUTOIT

Thanks. Works great, and simpler to read. For anyone else reading this: if you download the capx posted above (format_number2.capx) and don't want decimals, change the first action from:

Code: Select all
Set Text to "." & zeropad((foo*100)%100,2)


to

Code: Select all
Set Text to ""


Cheers,T
Don't lose your work. Backup your game with Dropbox.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,202

Post » Thu Feb 27, 2014 2:27 pm

A very nice method - thanks for the capx.
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,892


Return to How do I....?

Who is online

Users browsing this forum: kurtbal and 9 guests