zerofill an integer

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
Jezzy
Regular
Posts: 30
Joined: Wed Jun 21, 2017 2:18 pm
Contact:

zerofill an integer

#1 Post by Jezzy »

hello!

How would I do a 'zero filling' of an integer in Renpy in a text ?

For example : 1 becomes 01

In that case, I want all my character stats to be 2 digits long.

Code: Select all

text " {=cs_stats}{b}[player.con]{/b}" xpos 490 ypos 90 anchor(0,0)
Regards ^.^

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: zerofill an integer

#2 Post by Remix »

Ren'py uses a [] enclosed string interpolation (as you know with your [player.con] bit)
This sits on top of python .format methodology which tries to adhere to PEP 3101
Some Basic Samples

So:

[player.con:0>2]

Should do the trick
Frameworks & Scriptlets:

Post Reply

Who is online

Users browsing this forum: Google [Bot]