Setting the location of a game prop precisely

I’ve decided to tackle the task of trying out the Blender 2.5 Game Engine, including its Python API. I’m trying to find a way to position objects precisely - for instance, moving the object so it’s exactly at (3.0, 1.0, 1.0), or creating a new object and giving it a precise location, from a Python script. For some reason, for instance, the following will not work in a script (when linked in game logic through the “Python Script” controller):

bpy.context.scene.objects[‘GameObj’].location[0] += 3

However, just pressing “Run Script” in the Text Editor runs it perfectly fine… What am I doing wrong?
Thank you in advance for help.

You need to use the game engine functions

import GameLogic as GL
cont = GL.getCurrentController()
own = cont.owner
own.position = [1, 2, 3]

EDIT: Whoops sorry for not saying its for 2.49 :/. I need to switch to the 2.5 builds.

Here’s a blend file that shows what moffboffjoe said. It’s made for 2.5.

This way you can see how to use scripts in the BGE. Also, be sure you’re reading the right API. The line of code you wrote is for the regular Blender. You need to use the BGE Python API.


set_position.blend (65.2 KB)

@ moffboffjoe: This, I presume, would have worked in v2.49 and below, but it looks like in 2.50 there is no such thing as GameLogic anymore, at least even typing “import GameLogic” gives an error saying that there is no more GameLogic module… Do you know what it was replaced with? Thank you very much for your help!

EDIT: Whoops, yeah, looks like it was my bad - I confused the two APIs, and yeah, the example provided both by moffboffjoe and Wehrdo work! Thank you very much for your help! :smiley: