# (BGE) How to have a random font for each character in a text object?

I have made three similar, handwritten fonts. I'm trying to figure out a script (assuming this requires scripting) which would not only turn the player's input string into the text object's text - I already have this part - but also randomly select a different font for each character of the string in real time, so that it looks like handwriting, with convincing human errors/variations. But I just don't know what to do, or if it's possible. Help!

## 1 Answer

You have to add a separate text object for every character of your string.

Put a text object for every font you have on another layer, add a text game property to all of them and name them something meaningful. Then add an empty to the point where you want the text to start. The letters will be spawned there. Lastly execute this script:

import bge
import random

scene = bge.logic.getCurrentScene()
string = "string"
fontList = ["font1", "font2", "font3"]
empty = scene.objects["Empty"]

for character in string:
font = fontList[random.randint(0,2)]
object = scene.addObject(font,empty)
object["Text"] = character
empty.worldPosition.x = empty.worldPosition.x + 1


The variable string is the string you get from the user's input. The items in fontList are the names of the text objects on the separate layers. The object empty is of course your empty so you have to use its name.

Then you go through your string letter by letter and generate a random number. This number can't be higher than length of fontList, so in this example it's 0 to 2 (3 items). A random text object (the one you just generated, so in case of a 2 it's the object "font3") will be added at the empty's location, the object's text will be changed to the letter and the empty will be moved (you should of course adjust this movement for your needs) so that the next letter won't be added on top of the other one.