Text Node

What I’d like to do is have some text that pulls from a default list of words and randomizes it. like “hi” then it switches to “bye” and then “dude” with a set amount of time in between each. I messed around with Text Node for a bit but couldn’t get a good result. I’m making a private server for toontown. and I have this code for the phrases

import string

Randomizer = {'Loadings': ['Loading NameTags'
'Preparing Pies'
'Filling Squirt Guns'
'Settings Settings For Settings'
'Gathering Cog Suits'
'Loading Houses'
'Reloading The LoadingScreen'
'Animating Animations'
'Directing Tunnels'
'Coloring Golf Balls'
'Approving Toon Names'
'Restocking Gag Shops'
'Announcing Announcements'
'Deploying Fireworks'
'Making Toons Laugh'
'Catching Butterflies'
'Setting Snow Levels'
'Setting Times'
'Growing Trees'
'Recalculating Cakes'
'Squashing Bugs'
'looping Music'
'Repairing Signs'
'Loading accessories'
'Setting Boundaries'
'Repairing Musical Instruments'
'Destroying Classic Characters'
'CheckMate'
'Refining Karts']}

But I don’t think thats the right way, and i can’t tell because I don’t know how I would setup the code to get them to scroll through them and randomize them. any help is helpful. Thanks

To get a random element of a list use random.choice

import random

random.choice(Randomizer[ 'Loadings'])

What to do with it is up to you.

Thank you so much. What I did was

text=random.choice(Randomizer['Loadings'])

But a type error comes up mentioning ‘getitem’ after looking here farmdev.com/src/secrets/magicmethod/ I see the it is setup with getitem, I was wondering how I’d set it up if instead of the printing part

print '%-15s  %s' % (type(items), items)

I could set it as the text, but then that’d mean removal of the randomizer.

I think both you and me are posting too little code.

Try it like this:

import random

Randomizer = {'Loadings': ['Loading NameTags',
'Preparing Pies',
'Filling Squirt Guns',
'Settings Settings For Settings',
'Gathering Cog Suits',
'Loading Houses',
'Reloading The LoadingScreen',
'Animating Animations',
'Directing Tunnels',
'Coloring Golf Balls',
'Approving Toon Names',
'Restocking Gag Shops',
'Announcing Announcements',
'Deploying Fireworks',
'Making Toons Laugh',
'Catching Butterflies',
'Setting Snow Levels',
'Setting Times',
'Growing Trees',
'Recalculating Cakes',
'Squashing Bugs',
'looping Music',
'Repairing Signs',
'Loading accessories',
'Setting Boundaries',
'Repairing Musical Instruments',
'Destroying Classic Characters',
'CheckMate',
'Refining Karts']}

text=random.choice(Randomizer['Loadings'])
#do something with the now random text
print text 

I think that’d work, but it’d most likely display in the cmd opposed to directly on screen. Like lets say this.

Text=Loading(text='', pos=... 

if I were to input something into the text, what would it be? I tried putting the randomizer, but it needs getitem magic method, and I’m not entirely sure how to set that up with the structure of TextNode.

I’m not sure what you mean with getitem
It’s a special method that allows a ‘list like access’ if I dare call it that. If you have a list like test=[‘a’,‘b’,‘c’] then you can get the ‘a’ item using test[0], you can make your own class that has this method, but I don’t think it is relevant.

The root of the error is I think that you didn’t pass a list to random.choice()

By the bits of code you are posting I can’t make out what the code is supposed to do.

There are probably different and better ways to do it, but this should be a start:

from panda3d.core import *
import direct.directbase.DirectStart
from direct.interval.IntervalGlobal import *
import random

random_text =['Loading NameTags',
'Preparing Pies',
'Filling Squirt Guns',
'Settings Settings For Settings',
'Gathering Cog Suits',
'Loading Houses',
'Reloading The LoadingScreen',
'Animating Animations',
'Directing Tunnels',
'Coloring Golf Balls',
'Approving Toon Names',
'Restocking Gag Shops',
'Announcing Announcements',
'Deploying Fireworks',
'Making Toons Laugh',
'Catching Butterflies',
'Setting Snow Levels',
'Setting Times',
'Growing Trees',
'Recalculating Cakes',
'Squashing Bugs',
'looping Music',
'Repairing Signs',
'Loading accessories',
'Setting Boundaries',
'Repairing Musical Instruments',
'Destroying Classic Characters',
'CheckMate',
'Refining Karts']

def ChangeTextLoop():
    text.setText(random.choice(random_text))
    seq.start()

text = TextNode('node name')
text.setText(random.choice(random_text))
textNodePath = aspect2d.attachNewNode(text)
textNodePath.setScale(0.07)

seq=Sequence(Wait(1.0), Func(ChangeTextLoop))
seq.start() 

run()   

I don’t really think this is what you want, but this is what you asked for.

ok, thanks, I’ll try it out