Character Spacing (Got it)

I’ve almost finished writing a script, but I ran into a problem. How can I format the Text so that it is even, like columns. I attached a pic, and a blend of the problem (the blend has an example code)

Attachments

Charactor spaces.blend (168 KB)


I think you’ll have to make separate text objects.

Got it!

@Djorhan; Thanks for the reply, but I knew there was a way!

import GameLogic as gl

cont = gl.getCurrentController()
own = cont.getOwner()

a1 = str(own.a1)
a2 = str(own.a2)
a3 = str(own.a3)
name = str(own.name1)

space = (' ')

t = 10 - len(a1)
y = 10 - len(a2)
u = 10 - len(a3)
i = 10 - len(name)

a = space * t
b = space * y
c = space * u
d = space * i



b1 = a1 + (a)
b2 = a2 + (b)
b3 = a3 + (c)
bn = name + (d)



#if len(a1) < 5:
    
    
own.Text = str(b1 + bn + b2 + b3)

Attachments


Charactor spaces.blend (191 KB)

Well thanks I didnt even think about your solution. Im sure it’ll help me sooner or later :wink:

You may wish to try that with larger letters like ‘m’ and ‘w’. A good way to account for different width letters would be to create a dictionary with all of the letter widths, then add up the total length using it. You can find out the width of a space too, and using that work out how many spaces you need to put in.

E.g.


letterLength = {
' ' = 0.4,
'a' = 1.0,
'b' = 1.0,
...
'm' = 1.3,
'n' = 0.9,
...
'x' = 0.9
}

string = "Test line WWwwwwWW"

total = 0.0
for letter in string:
    total += letterLength[letter]