Odd problem with p3d

My program runs fine when I run it normally. If I pack it into a p3d, it crashes. I don’t understand the error either.

Traceback (most recent call last):
  File "C:\Users\Chris\workspace\BattleCraft\com\tumblr\montawk\main.py", line 31, in start
    self.game = Game()
  File "C:\Users\Chris\workspace\BattleCraft\com\tumblr\montawk\Game.py", line 24, in __init__
    self.environment = Environment(self)   
  File "C:\Users\Chris\workspace\BattleCraft\com\tumblr\montawk\Environment.py", line 94, in __init__
    myChunk = Chunk(x, y, z, self, self.blocks, self.node, self.blockTexture, x * numYChunks * numZChunks + y * numZChunks + z)
TypeError: __init__() takes at most 5 arguments (9 given)
:task(error): Exception occurred in PythonTask start
Traceback (most recent call last):
  File "C:\buildslave\release_rtdist_win32\build\panda3d\built_cmu\direct\p3d\AppRunner.py", line 636, in run
  File "C:\buildslave\release_rtdist_win32\build\panda3d\built_cmu\direct\task\Task.py", line 502, in run
  File "C:\buildslave\release_rtdist_win32\build\panda3d\built_cmu\direct\task\Task.py", line 460, in step
  File "C:\Users\Chris\workspace\BattleCraft\com\tumblr\montawk\main.py", line 31, in start
    self.game = Game()
  File "C:\Users\Chris\workspace\BattleCraft\com\tumblr\montawk\Game.py", line 24, in __init__
    self.environment = Environment(self)   
  File "C:\Users\Chris\workspace\BattleCraft\com\tumblr\montawk\Environment.py", line 94, in __init__
    myChunk = Chunk(x, y, z, self, self.blocks, self.node, self.blockTexture, x * numYChunks * numZChunks + y * numZChunks + z)
TypeError: __init__() takes at most 5 arguments (9 given)
:TaskManager: TaskManager.destroy()

I’m passing 9 args to the Chunk constructor, but the constructor is expecting the 9:

class Chunk():
    
    def __init__(self, x, y, z, environment, blocks, node, blockTexture, geomId):

I’m not sure why it thinks it only takes 5

Two ideas:

(1) Maybe some other class is shadowing your Chunk class. Try (temporarily) renaming your Chunk class to something else to prove it is not.

(2) Maybe the error is not actually on that line, but on some other hidden line? This is more difficult to track down, but you can run it interactively if you use -D on the packp3d command, and -i on the panda3d command. Then you can inspect your call stack and your objects more carefully with pdb.

David

Yep. Must be a builtin module called Chunk.py somewhere. Thanks.

Actually, builtins never shadow explicit imports. So it probably came in with an “import *” syntax.

You can check to be careful with your import statement order. Make sure any imports of the form “from X import " are performed first, before imports of the form “from X import A, B”, so there’s no possibility of the "” syntax accidentally bringing in symbols you didn’t expect and shadowing symbols you meant to bring in.

Better yet, avoid the “*” syntax altogether, and always import exactly what you mean to. (I frequently don’t take the time to do this, because I like the convenience of not having to type every darn thing I want to use. But it can lead to problems like this.)

David

Thanks for the advice. I actually didn’t have any import * statements, so I’m not quite sure what was causing it. It doesn’t really matter to me that the name is slightly different; since it’s working, I’ll just leave it as is.