inheritance of Actor + DirectObj


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 ??
class Ralph(, 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 import Actor

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

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