Hi, I´m new to panda3D and to python. I have already made a working demo of my game before, but for better organization I started to use classes(which I learned recently), then, my game do not even starts now.
It appears it´s because I do not know how to read/set variables between classes. I have made a level class and a player avatar class:
#Player class Avatar(DirectObject): def __init__(self): self.loadActor() self.eventCapture() def loadActor(self): self.player = render.attachNewNode("player") self.playerActor = Actor.Actor("models/player") self.playerActor.setScale(0.1,0.1,0.1) self.playerActor.reparentTo(self.player)
#Level class Level(): def __init__(self): self.loadScenario() def loadScenario(self): self.Level = loader.loadModel("models/peaks") self.Level.reparentTo(render) self.Level.setScale(10,10,10) self.Level.setPos(0,0,-9) playerStartPos = self.Level.find("**/start_point").getPos() player.setPos(playerStartPos)
The level is failing to set the player position in class Avatar.I get this error:
DirectStart: Starting the game. Known pipe types: wglGraphicsPipe (all display modules loaded.) Traceback (most recent call last): File "tsm.py", line 360, in <module> Levelobject = Level() File "tsm.py", line 254, in __init__ self.loadScenario() File "tsm.py", line 263, in loadScenario [b] player.setPos(playerStartPos) NameError: global name 'player' is not defined[/b] **** End of process output ****
I would be gratefull for any help on this problem, I have switched from blitz3d, and I think panda3d(and python) is a very reasonable and powerfull tool for game development, if I know how to use it.