import class from python text block into another in BGE

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

strattonbrazil
Posts: 7
Joined: Wed Sep 06, 2006 4:36 pm

import class from python text block into another in BGE

Postby strattonbrazil » Thu Jul 26, 2012 6:21 am

I have a text data block called "startup" that is called when the blender game engine starts. In the code, I print "starting...", which I see in the console and declare a class called Foo. I have another block of code called "keyboard_left" that is called when the left arrow key is pressed. In this code, I'm trying to import the Foo class declared in startup, but I get an error saying that module doesn't exist.

In the "startup" data block

Code: Select all

print('starting...')

class Foo(object):
    pass


In the "keyboard_left data block"

Code: Select all

from startup import Foo


And when I press the left key, I get the following error...

Code: Select all

Traceback (most recent call last):
  File "keyboard_left", line 3, in <module>
ImportError: No module named startup
Blender Game Engine Finished


Code in the startup data block as already run though. Does blender throw this away after a controller is called? If so, how do I declare classes/globals to be used by other python controllers? Or am I just namespacing the import incorrectly?

CoDEmanX
Posts: 894
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Postby CoDEmanX » Thu Jul 26, 2012 11:30 am

i believe import requires scripts to be saved as files on harddrive, having just a blender text block doesn't work i think
I'm sitting, waiting, wishing, building Blender in superstition...

strattonbrazil
Posts: 7
Joined: Wed Sep 06, 2006 4:36 pm

Postby strattonbrazil » Fri Jul 27, 2012 2:37 am

Alright. I may just keep things in a dictionary in a global list just to keep everything inside blender. Thanks.


Return to “Python”

Who is online

Users browsing this forum: No registered users and 1 guest