No module named GameLogic

Hi,

i am very new in Blender game engine.
i created a python code that i’d like to add in game engine.
So i started to study how to connect python code with game engine.
Before i work with my python code, i started with a simple example from ‘blender game kit’ gook.
When i tried following simple example code:

 import GameLogic

 controller = GameLogic.getCurrentController()
 owner = controller.getOwner()

 print owner.getPosition()

it gives me import error: “No module named GameLogic”

So i typed “import GameLogic” in the python console it gives me the same error.
Can somebody help me with this?
I can’t even get started anything because of that.

thanks in advance.

First, open a Logic Bricks Window (F4) and choose an Object You like. Now, You have to connect a Python Controller with a Sensor (maybe an Always). Insert the Scripts Name into the Controller and start the Game with P-Key. Now the Game and Script will run. :wink:
Doc

http://mywebpage.netscape.com/YinYangEvilSane/BlenderStuff/game_script.png

notice the always sensor has no pulse buttons set, it will only pulse on the very first frame the object exists

once you have the logicbricks setup you start the game from the game menu or with the P key [put your cursor in the 3d view first]

print statements go to the console window [same as other scripts run in blender]

interesting, you have the exact same code as someone else asked about before [when I made that pic]… I guess I hadn’t read the gamekit book enough [or it is generic enough code] to notice…

Thanks guys
i guess the problem was that i tried ‘alt-p’ from the text window to run the python script associated with the game engine.
All i needed is press ‘p’ from blender 3d window!!
Thanks again.

By the way, one more thing i am curious about is when i tried the code above, it seems the python code is executed more than once - actually it seems it is executed endlessly until i press ‘esc’ key.
Does anyone know how to make it run only once?

By the way, one more thing i am curious about is when i tried the code above, it seems the python code is executed more than once - actually it seems it is executed endlessly until i press ‘esc’ key.
Does anyone know how to make it run only once?

import it, or link a sensor with pulse mode off

Okay, now i got how it works!
thanks a lot