BGE and Python - Editing position

HI!

I try to move and object coping an other object position by python.

This is my try :

http://www.kino3d.com/forum/files/pythonbge.jpg

When I start the Game nothing appens!
Thanks for helps

You are using the wrong Python API. That is the Blender Python API, not the Game Engine API.

Find the Blender 2.49 Game Engine API here: http://www.blender.org/documentation/249PythonDoc/GE/index.html
With examples here: http://www.tutorialsforblender3d.com/GameFunctions/ClassIndex_1.html
Find the Blender 2.48a Game Engine API here: http://www.tutorialsforblender3d.com/GameFunctions/Index_248/ClassIndex_1.html

Since you are just learning Blender’s Python interface, I highly recommend that you upgrade to Blender 2.49 and learn the Blender 2.49 Game Engine API. The API has changed significantly since 2.48a, and even if you learn Python for 2.48a, you will have to re-learn it for 2.49.

That said, I have not completely learned the 2.49 API yet, and I actually don’t yet know how to do what you’re trying to do. My guess would be to do something like this:

scene = GameLogic.getCurrentScene()

cube = scene.objects["OBCube"]
sphere = scene.objects["OBSphere"]

cube.position = sphere.position

(I just tried that, and it works. See attached.)

Attachments

PythonMovePosition.blend (36.1 KB)

Thanks it work!

The only problem that i see is that the python code run only with a keybord Sensor,

The always Sensor doesnt work.

Why ?

Thanks for help

Attachments

alwayno.blend (135 KB)

Because true pulse is off, the always sensor only fires during the first frame. To turn on true pulse, toggle the little square button in the top left corner of the always sensor (labeled “…”)