Making text appear on random blocks in game engine...

I am making a quiz game. Each question has 4 possible answers to it. I have made 4 clickable buttons on which I want to display the answers… I have a total of 50 questions… Shown randomly using a python script. I want to show the answers on the buttons I created for them, the 4 options may arrange themselves randomly on each of the 4 buttons… How do I do that?

for example in the above image… this equation has 4 options, x=2,x=4,x=5,x=6. How do I make these options appear on random blocks everytime? And how do I change the answer choices when a question is changed without hard coding the entire thing.


Try using a blender ‘text’ object (shift-A in object mode, select ‘Text’). In your code, you can change what the text actually says via object.text = ‘____’. Parent your text objects to the buttons (Select the text object, shift select the button, then Ctrl-P).

Yeah but that still leaves the problem of the answers reshuffling themselves every time a new question comes up.

Well you can just use a list/random.randint() function for python:

There are many ways, and many randomizing algorithms for python. One way to implement this is through a list. For each question, you can store the answers in a list. Then, call random.shuffle(yourlist) to randomize the list. Afterwards, you can enumerate through the list and assign the answers as such: object1.text = yourlist[0], object2.text = yourlist[1]…etc.
Or if you put the objects themselves in lists, you can simply for check in range(0, limit) and do objectList[check].text = yourlist[check]

You can check out the range() and shuffle() functions here: