1

What is going on. I have looked at other solutions on stack overflow but non seem to work from what I have seen. I have a base object with a method that changes the value of the base attribute. When I call the base function in a child class (Inheritance) I get that the child class does not have the attribute "baseAttribute"

class GameObject(object):
 #This is the base class for gameObjects
 def __init__(self):
     self.components = {}

 def addComponent(self, comp):
     self.components[0] = comp #ignore the index. Placed 0 just for illustration

class Circle(GameObject):
 #circle game object 
 def __init__(self):
     super(GameObject,self).__init__()
     #PROBLEM STATEMENT
     self.addComponent(AComponentObject())
     #or super(GameObject,self).addComponent(self,AComponentObject())
     #or GameObject.addComponent(self, AComponentObject())

EDIT: Apologies, I never originally passed in a self.

0

2 Answers 2

4

Simple - leave out the second self:

self.addComponent(AComponentObject())

You see, the above actually translates to

addComponent(self, AComponentObject())

In other words: in essence "OO" works on functions that have an implicit this/self pointer (however you name that) as argument.

Sign up to request clarification or add additional context in comments.

Comments

0

You are using incorrect arguments for .addComponent() method.

# ...

class Circle(GameObject):

 def __init__(self):
     super(GameObject,self).__init__()
     # NOT A PROBLEM STATEMENT ANYMORE
     self.addComponent(AComponentObject())
     # ...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.