Perhaps there is no function like this in blender, but how do I use python to display text randomly from an array? Essentially, during a loading screen I want to be able to scrub through different "tips" randomly using python; these tips will be displayed in a text-box inside the game. Thank you. enter image description here


1 Answer 1


ah this is a simple python problem.

if I understand correctly all you have to do is

import random


import random

of course actually displaying them in the game itself is possible, just slightly more complicated.

also next time please post a python question in a python thread.

since this is technically a duplicate: https://stackoverflow.com/questions/306400/how-to-randomly-select-an-item-from-a-list

  • $\begingroup$ Thank you; however, I reworked my code a little using your hint about random.choice instead of random.shuffle. This is my current code: 'import bge import bpy import random import time tips = ["Press space to switch between perspectives!", "In 3d mode? Press 'e' to jump!", "Eat more veggies!", "Watch the timer!", "Does anybody actually read these things?"] count = 0 while count == 0: count = count + .5 for i in tips: bpy.data.objects["Textbox"].data.body = random.choice(tips) time.sleep(.5) if count == 5.5: count = 0' $\endgroup$ Jan 13, 2020 at 21:43
  • $\begingroup$ Formatting in comment form sucks... sorry. It doesn't work when I hit play, only in object mode and it iterates through the list everytime I end the game engine. How do I make it work in the game engine was the question, which is the only reason I posted it here/ I do apologise for the misunderstanding and inconvenience! $\endgroup$ Jan 13, 2020 at 21:47
  • $\begingroup$ Ah, I don't believe your code is the issue, you probably have an actuator with both skips down, tic those off and it should work. But now I'm just taking shots in the dark because I don't have your .blend. -- or to have it display something different every time, change the skip counter. $\endgroup$
    – Frederick
    Jan 14, 2020 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.