code question

Why didn’t this code change the text?

 import bge
# create a dictionary of phone numbers
own = bge.logic.getCurrentController().owner
own.text = { "Fred"     : "555-1111",  
"Alison"   : "555-2222", 
 "George" : "555-3333", 
 "Rachel"  : "555-4444" }

# get Rachel's phone number
number = phonebook["Rachel"]
# print Rachel's phone number
print(number)
########   it will print
555-4444
########

i cant tell, something dont look right with the snippet…but it looks like your defining own.text as the entire dictionary. I dont see where phonebook is being defined but yet you are pulling rachel from it. Is own a text object? maybe something like




phonebook = { "Fred"     : "555-1111",  
"Alison"   : "555-2222", 
 "George" : "555-3333", 
 "Rachel"  : "555-4444" }

# get Rachel's phone number
number = phonebook["Rachel"]
# print Rachel's phone number
print(number)

#then
textobject["Text"] = number


Heres your script in a blend

i have the script attached to the cube and not the text object. The script defines the text object. Also it is set to run only once or you will be defining the dictionary everyframe doing it this way

textchange.blend (403 KB)