How to align text to the right?

How to align text to the right? It automatically aligns to the left in-game.
I’ve seen no option to change it. Is there anything to change it or do you have to use python?

Pretty sure you can just change the scale on the horizontal axis to -1. There’s some kind of simple trick like that, anyway.

Hmm, that doesn’t seem to work.

Thanks, but it reversed my text?
I’ve used this:

oldText = str(j['Number'])
def reverseText(oldText):
    length = len(oldText)
    newText = ""
    for x in range(length):
        newText += oldText[(length-1)-x]
    return newText
own['Text'] = reverseText(str(j['Number']))

EDIT: It seems it requires flipping normals for a text object and I don’t know how to do it.

The only thing that helped me a bit is this, but it’s not ideal:

own['Text'] = str(j['Number']).rjust(5, '0')

Hi @Saranoske,
I have 3 suggestions to offer.

  1. Use BLF text, text alignment is very easy to implement with it
  2. Use UPBGE 0.3, text alignment works for it
  3. Manually place it, this isn’t obviously ofc, but it makes due sometimes.
1 Like

you can use string formatting for this

txt = "hello world"

print(f"[{txt:>15}]")
print(f"[{txt:^15}]")
print(f"[{txt:<15}]")

outputs

[    hello world]
[  hello world  ]
[hello world    ]
1 Like

or if you have a high score where you want leading zeros


score = 1234

print(f"{score:0>8}")

outputs:
00001234
1 Like

I have tried your suggestion but it gives me a syntax error.

Python error compiling script - object 'grid_num', controller 'Python':
  File "Text_Properties", line 27
    print(f"[{txt:>15}]")
                       ^
SyntaxError: invalid syntax

I’m using Blender 2.79b and it seems that it has an older version of Python where this kind of code is not supported.

then use the old format

txt = 1234

print("{:0>8}".format(txt))
1 Like

Thank you, this works but it seems it’s the same like this:

print(txt.rjust(5, '0'))

Is there a way how to make those 0s invisible? The blank space is too short for this and makes it look like it’s aligned to the center.

just remove the 0 from the format string

txt = 1234

print("{:>8}".format(txt))

Yes, it works but I’m using a text object in Blender. With this, it looks like it’s aligned to the center.
TextAlign_001

With 0s it’s ok.
TextAlign_002

how does you code look like

txt = str(own['Number'])
own['Text'] = "{:0>5}".format(txt)

or without 0s

own['Text'] = "{:>5}".format(txt)

This is basically what you’ve suggested.

The problem is the blank space. It’s too short.

i have used this in the past without any problem.

There is no problem here, it’s the blank space from the font that’s too short.

then use a different font, like a mono space one, the blender text object have limitations.

Yes, that’s the main problem. But thank you for your help.

you can always use different fonts for different things, like a mono space one for numbers and a regular one for other stuff.