python questions

Hi all !

can you help me about this :

i need to copy a property from an object to another, but in python !

and how to custom property name like that :


property = another+"i"

i is a int variable

thx :wink:

You should probably explain what your doing better. You can get other objects in the scene with:
import GameLogic
scene = GameLogic.getCurrentScene()
obj = scene.getObjectList()[ā€œOBobjectNameā€]

Once you have the object, you have a copy of all it’s properties like
health = obj.health + 10

ok thx it’s ok for the first one.

I explain what i want to do :

i want to duplicate an object with parented objects.

the parented objects need to know some property of the parent.
it’s possible with the solution you give.

but when you duplicate an object, the new object is rename (like armature.001 => armature.002)

so the python script take always the property of armature.001 and i want it to take it from armature.00x

i can’t write infinite script for all duplicated objects.

i remember in action script (flash) that it was possible to to that:

property = [object+ā€œiā€].property

with i a variable

and the cumputer read ( i=10 ):

property = object10.property

an other idea : if i can found the parent object of an object, my problem is over.

thx :slight_smile:

You can change the last numbers to a string and get information. This isn’t the code you would need but might help you understand what you need to do.


name = "OBArmature"
n = 0.0
for i in range(1,10):
     n = n + .001
     print name + str(n)[1:]

Another thing you can do is keep a list of names:


GameLogic.Armatures = ["OBArmature","OBArmature.001"]
for name in GameLogic.Armatures:
     obj = scene.getObjectList()[name]
     obj.property = obj.property + 10


For child objects it is easy to find the parent with getParent().
I couldn’t find a way to identify the children of an object.