Skip to content

Text Templates

Text templates can contain python format strings to show text placeholder.

This is an example which will show the player 1 score of the previous game as number:

Player 1 score: {machine.player1_score:d}

Current score (during a game only):

Score {current_player.score:d}

Any variable needs to be enclosed in {}. Either you can use {variable} or {variable:format_string}. Any python format string will work here.

Common format strings

Assuming variable has a value of 1337.

Alignment and Padding

Left aligned and padded to 10 characters:

{variable:10}

Output:

"1337      "

Right aligned and padded to 10 characters with zeros:

{variable:0>10}

Output:

"0000001337"

Centered and padded to 10 characters with spaces:

{variable:^10}

Output:

"   1337   "

Number as float (2 decimals):

{variable:5.2f}

Output:

" 1337.00"

Number as integer:

{variable:5d}

Output:

" 1337"

Truncating long strings

Centered and padded to 10 characters with spaces:

{variable:.3}

Output:

"133"

Something missing or wrong? You can fix it!

This website is edited by people like you! Is something wrong or missing? Is something out of date, or can you explain it better?

Please help us! You can fix it yourself and be an official "open source" contributor!

It's easy! See our Beginner's guide to editing the docs.

Page navigation via the keyboard: < >

You can navigate this site via the keyboard. There are two modes:

General navigation, when search is not focused:

  • F , S , / : open search dialog
  • P , , : go to previous page
  • N , . : go to next page

While using the search function:

  • Down , Up : select next / previous result
  • Esc , Tab : close search
  • Enter : go to highlighted page in the results