Previous Thread  Next Thread

chat icon import class from python text block into another in BGE

strattonbrazil

Posted: Thu Jul 26, 2012 5:21 am
Joined: 06 Sep 2006
Posts: 7
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:

print('starting...')

class Foo(object):
    pass


In the "keyboard_left data block"
Code:

from startup import Foo


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

Code:

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?
Reply with quote


CoDEmanX

Posted: Thu Jul 26, 2012 10:30 am
Joined: 05 Apr 2009
Posts: 680
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...
Reply with quote


strattonbrazil

Posted: Fri Jul 27, 2012 1:37 am
Joined: 06 Sep 2006
Posts: 7
Alright. I may just keep things in a dictionary in a global list just to keep everything inside blender. Thanks.
Reply with quote


 
Jump to:  
Powered by phpBB © 2001, 2005 phpBB Group