Problem with python script: copy z-position

Hey guys i’ve got a problem with the following script. i wanna copy the z position of one object to another. Hope you can help me

# get the current controller
controller = GameLogic.getCurrentController()
# get the object this script is attached to
obj = controller.owner
# get current scene
scene = GameLogic.getCurrentScene()
# get list of objects in scene
objList = scene.objects
# get Cube object
cube = objList["OB" + "Cube"]    # Cube
# set the z position
obj.position[2] = cube.position[2]

it should work. but safer way is probably to write:


obj.worldPosition = (obj.worldPosition[0], obj.worldPosition[1], cube.worldPosition[2])

Thank you thank you thank you!!! It works! I tried it out thousands of times before.
without this i couldn’t go on with my monster truck game.
Thanks alot!!!