make the object's current name the name of a global property?(python)

let’s say I got the object’s name via python and stored it in a variable called name then wanted to make a global property of GameLogic.[object’s current name] doing

GL.name

doesn’t work so how would I do it?

What doesn’t work? Saving a name property in GameLogic works fine for me…

For example:


import GameLogic as g

cont = g.getCurrentController()
g.name = cont.owner.name

And then I have another script…


print GameLogic.name

Which correctly prints out the first object’s name…

?

since 2.49 object names are read only, renaming caused problems

Python script error from controller “cont#CONTR#2”:
Traceback (most recent call last):
File “mouse.py”, line 29, in <module>
AttributeError: “name” is read only

How about you save it to a dictionary instead?


### Initiate the dictionary ###
if not hasattr(GameLogic, "myObjects"):
    GameLogic.myObjects = []

### Assigning the global variable  ###
obj = GameLogic.getCurrentController().owner

GameLogic.myObjects[obj.name] = obj # Put whatever value you wanted to put here

I’ll try that thanks.

Ah, maybe I misunderstood what you meant? I thought you wanted to save the name property of an object and put it in GameLogic… but you want to change the name of an object instead?

Can you explain a bit more as to why you need to do it / what use it has to change the name? You could always just have a string property on the object which you could change…

-Sam