inheritance of Actor + DirectObj

Hi!

I am a newb but managed to get my Panda moving around after browsing a few hours of the docs :wink:

My problem: I want to make a class (Ralph) of type Actor and DirectObj (an Actor that listens to Events). The code is not elegant and I could use a little hint how to do it nicer. Every time I create an instance of Ralph I have to call makeAccept() to initialize the controls. A nicer way would be to do that at the init() but I get lots of errors when trying to overload that function (surely because the way I do it is not proper).


#subquestion: does I really need to inherit from direct.actor.Actor.Actor ??
class Ralph(direct.actor.Actor.Actor, DirectObject.DirectObject):
	def makeAccept(self):

          self.accept('arrow_right', self.moveRight)
	  self.accept('arrow_left', self.moveLeft)
 	  self.accept('arrow_up', self.moveUp)
	  self.accept('arrow_down', self.moveDown)
	
	def moveRight(self):
	  self.setX(self.getX()- 0.2)

	def moveLeft(self):
	  self.setX(self.getX()+ 0.2)

	def moveUp(self):
	  self.setY(self.getY()- 0.2)

	def moveDown(self):
	  self.setY(self.getY()+ 0.2)

Actually, Actor already does inherit from DirectObject, indirectly, so you don’t need to inherit from it again.

In Python, whenever you do multiple inheritance, you must overload your init() function to call up to both base classes, like this:

from direct.actor.Actor import Actor

class Ralph(Actor, MyOtherClass): 
  def __init__(self):
    Actor.__init__(self)
    MyOtherClass.__init__(self)
    ... any other initialization you want to do ...

Note that, if you import Actor via the syntax “from direct.actor.Actor import Actor”, instead of “import direct.actor.Actor”, then you can just refer to the class name as Actor, instead of as direct.actor.Actor.Actor.

David