Problem animating an Actor that is part of a class I made.

I’m experimenting a little bit with panda3d and I’m trying to let a class load some models during it’s initialization. And then I could access these models using the object.

This is an example of one of these classes.

from panda3d.core import NodePath
from panda3d.core import PandaNode
from import Actor
class HWscene_Class:
    def __init__(self, name="HWscene"):
        self.root = NodePath(PandaNode(name))        
        #self = self.attachNewNode(name)
        self.environ = loader.loadModel("models/environment")
        self.environ.setScale(0.25, 0.25, 0.25)
        self.environ.setPos(-8, 42, 0)
        self.pandaActor = Actor("models/panda-model",{"walk": "models/panda-walk4"})
        self.pandaActor.setScale(0.005, 0.005, 0.005)

The code in the main file is this

HWscene = HWscene_Class()

This opens the the hello world scene. And for wath I think it should also animate the panda. But It doesn’t. It only stands still.

Did I mis anithing. I am very new.

This is probably because you are not keeping a reference to the class and it is destructing (and thus the Actor destructing). This is mentioned briefly in the manual:
Something like this might work:

class Game(DirectObject):
    def __init__(self):
        self.HWscene = HWscene_Class()


Thanks. It solved my problem. I didn’t know I had to put the self. in front of the variable. In my last project I didn’t use a OOP language. I need to remember some things again.