No module named GameLogic

Hi Blenderers,

I have really tried to find the answer before posting this, please don’t say: “do a search on Python, there’s tons of tutes you moron.”

WinXP-Pro, Blender 2.36, Python 2.3.4 (installed in C:\python23). Win-XP environment variable PYTHONPATH has been set to: C:\PYTHON23;C:\PYTHON23\DLLS;C:\PYTHON23\LIB;C:\PYTHON23\LIB\LIB-TK
I’ve tried this as both a system and a user-specific variable. Rebooting just in case. Within Blender User Prefs, File Paths, Python is set to C:\python23. Ctrl+U to save prefs, and restart blender just in case. When I launch Blender, the console shows no errors. I split my window, open a new text file, type:

import sys
print sys.path

then press Alt+P and the console shows:

['C:\\PYTHON23', 'C:\\PYTHON23\\DLLS', 'C:\\PYTHON23\\LIB', 'C:\\PYTHON23\\LIB\\LIB-TK', 'C:\\Program Files\\Blender Foundation\\Blender\\python23.zip', 'C:\\Program Files\\Blender Foundation\\Blender', 'C:\\PROGRA~1\\BLENDE~1\\Blender', 'C:\\Python23\\lib\\site-packages', 'C:\\Python23', 'C:\\Python23\\lib\\site-packages', 'C:\\python23', 'C:\\Program Files\\Blender Foundation\\Blender\\.blender\\scripts']

But, if I start a new text file and type:

print dir(GameLogic)
then press Alt+P and the console errors with:

Traceback (most recent call last):
  File "Text.001", line 5, in ?
NameError: name 'GameLogic' is not defined

If I start a new text file and type:

import GameLogic

then press Alt+P and the console errors with:

Traceback (most recent call last):
  File "Text.001", line 5, in ?
ImportError: No module named GameLogic

What other steps must I take to fully “hook-up” Python with Blender?

TIA!
-potus98

Stupid questions (mine), but did you do an “import Blender” first?

GameLogic is only available when the game engine is running.

Martin

…did you do an “import Blender” first?

No. So I followed your suggestion and tried adding “import Blender” but the behavior remained the same. The “import Blender” line seemed to work (no errors generated) but the script still generated the same error when it reached the GameLogic line.

GameLogic is only available when the game engine is running.

Yes, I’ve seen that mentioned a lot. The problem was, when I activated the game engine with “P”, that’s all Blender would do. I could not then move my focus to the text window to type “Alt+P”.

The good news is; I am now able to access the GameLogic module! The problems I’ve encountered so far are due to:

  • I’m a Blender GameEngine novice
  • I’m a Python newbie
  • Even the “basic” Blender+Python tutorials I’ve found assume just a little too much.

Based on many of the other posts I’ve read, I’m not the only person who struggles to get over this initial Blender+Python hump. Now that I know the step-by-step (for total noobs) process, I will post a mini-tutorial to this thread to help future forum searchers.

Ok, do this…

Insert an empty into your scene
go to the game buttons
make it look like the setup that I show for my script here

http://guitargeek.superihost.com/snapshot/

Then when you run the game it will activate your script on a key press. You could make it a specific key if you wanted I guess.