NameError when running from a P3D

Hello everyone!

I am definitely a newb at this stuff, so I can’t even begin to tell you if I have structured my game right here. Basically what’s happening is when I run my game that I packed to a P3D file using ppackage it gives me a NameError for my custom modules built for the game. Everything works fine when running the main.py prior to packing it all into a P3D.

Here’s what the console is spitting back at me…

:util: Reading /mf/config.prc
DirectStart: Starting the game.
:display: loading display module: libpandagl.so
:display: loading display module: libtinydisplay.so
Known pipe types:
  glxGraphicsPipe
  TinyXGraphicsPipe
  TinyOffscreenGraphicsPipe
(all display modules loaded.)
:ShowBase: Default graphics pipe is glxGraphicsPipe (OpenGL).
:pnmtext: Loaded font Perspective Sans Regular
:display: Unable to set window properties: !undecorated 
:ShowBase: Successfully opened window of type glxGraphicsWindow (OpenGL)
:audio: NullAudioManager
:audio: NullAudioManager
:ShowBase: __dev__ == 0
:text: Loading font /mf/fonts/pirulen.ttf
:pnmtext: Loaded font Pirulen Regular
Traceback (most recent call last):
  File "/root/pandaworker/panda3d-1.7.0/built_cmu/direct/showbase/Messenger.py", line 352, in __taskChainDispatch
  File "/root/pandaworker/panda3d-1.7.0/built_cmu/direct/showbase/Messenger.py", line 410, in __dispatch
  File "/root/pandaworker/panda3d-1.7.0/built_cmu/direct/p3d/AppRunner.py", line 493, in __startIfReady
  File "VFSImporter", line 153, in load_module
  File "/host/Users/chompy/Documents/Syncup/Game/ShadowOfADream/panda3d/main.py", line 77, in <module>
    shared.ground = Platform()
NameError: name 'Platform' is not defined
:task(error): Exception occurred in PythonTask Messenger-default
Traceback (most recent call last):
  File "/root/pandaworker/panda3d-1.7.0/built_cmu/direct/p3d/AppRunner.py", line 411, in run
  File "/root/pandaworker/panda3d-1.7.0/built_cmu/direct/task/Task.py", line 496, in run
  File "/root/pandaworker/panda3d-1.7.0/built_cmu/direct/task/Task.py", line 454, in step
  File "/root/pandaworker/panda3d-1.7.0/built_cmu/direct/showbase/Messenger.py", line 352, in __taskChainDispatch
  File "/root/pandaworker/panda3d-1.7.0/built_cmu/direct/showbase/Messenger.py", line 410, in __dispatch
  File "/root/pandaworker/panda3d-1.7.0/built_cmu/direct/p3d/AppRunner.py", line 493, in __startIfReady
  File "VFSImporter", line 153, in load_module
  File "/host/Users/chompy/Documents/Syncup/Game/ShadowOfADream/panda3d/main.py", line 77, in <module>
    shared.ground = Platform()
NameError: name 'Platform' is not defined
:TaskManager: TaskManager.destroy()
:display: Closing glxGraphicsWindow
Successfully joined thread: 0
Failure on startup.

Platform is the name of the first module it tries to load. I didn’t do anything special(I thought) to load it into my main script.

from platform import *
shared.ground = Platform()

That’s how I loaded it essentially. I am loading it into my ‘shared’ module so that all the modules that also import the ‘shared’ module can use it. Perhaps I am doing this totally wrong here. This is something I just started using, and am not really all that familiar with how Python pushes it’s variables around between modules, so to speak.

Let me know if more information is needed!

As for the game I am working on, it’s called “Shadow of A Dream.” I have screenshots and information on it in my blog, linked in my sig. I am going for a metroid like platformer with a Diablo like skill system. So far I am pretty pleased with my progress. I’ve really enjoyed working with the Panda3D engine and plan to use it for future projects as well.

Anyways thanks for any help you guys can offer me and forgive me if this is already addressed somewhere else, I swear I searched the forums throughly first! >_<

What is “platform”? Is it a module like platform.py, or is it a directory called “platform” that contains Platform.py?

Try importing it explicitly, e.g. “from platform import Platform”. The generic importer can cause problems with directory names; and it makes it hard for packp3d to figure out which .py files you meant to include in your package.

David

It’s “platform.py” and it’s not in a directory. So I don’t know if what you are suggesting would help in this cause but I’ll give it a shot.

Thanks!

Update:

After trying “from platform import Platform” I now get this…

ImportError: cannot import name Platform

Seems like it’s just not reading it right or maybe it think it’s a directory or something. What do you think?
[/code]

Ah, I know what it is. There’s a Python system module called “platform”, which is getting confused for your own platform.py.

Probably we should do a better job of ensuring that your local filenames correctly shadow the system filenames, but in the meantime, just rename your platform.py to something else.

David

That was it! I needed to change the name anyways as the Platform class really deals with loading up the entire level and not just the platforms.

I’m glad I asked about this, I probably wouldn’t have figured that out on my own. Thanks a lot!!