showing numerical variables with commas

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
OldFootnote
Newbie
Posts: 5
Joined: Mon Apr 16, 2018 1:36 am
Contact:

showing numerical variables with commas

#1 Post by OldFootnote »

Hi everybody!

I have a really simple question that I can't find the answer to.

I have this money system in my game, and I show the player how much money they have with a variable and simple text in a screen:

Code: Select all

default gold = 10000

screen money:
	frame:
        	xpadding 5
        	ypadding 5
        	xalign 0.86
        	yalign 0.05
        
        	hbox:
        		text "[gold] G"
This works fine, except instead of '10,000' the text will show '10000'. I tried putting a comma in the variable, but doing so makes it so I get an error every time I try to do math on it ('-=' '+=' etc.)

My question is, is there a way to add commas to large-numbered variables when you want to show those variables to a player?

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2400
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: showing numerical variables with commas

#2 Post by Ocelot »

Use python formatting:

Code: Select all

text "{:,} G".format(gold)
< < insert Rick Cook quote here > >

OldFootnote
Newbie
Posts: 5
Joined: Mon Apr 16, 2018 1:36 am
Contact:

Re: showing numerical variables with commas

#3 Post by OldFootnote »

Thanks! It works like a charm.

Does this also work when you want to show the variable in the script?

for example:

Code: Select all

label moneycheck:

	mc "I have [gold] left."
	
Edit: Nevermind, I figured it out. Thanks again for the help!

Post Reply

Who is online

Users browsing this forum: Semrush [Bot]