I have a class that is inheriting from another class, and I get the issue:
Traceback (most recent call last):
File "main.py", line 45, in <module>
class Player(Entity):
File "main.py", line 53, in Player
self.image = pygame.image.load('sam_stand.png')
NameError: name 'self' is not defined
These are the classes:
class RigidBody(object):
def __init__(self, (x, y), size, mass=1):
self.x = x
self.y = y
self.size = size
self.mass = mass
self.thickness = 0
self.angle = 0
self.drag = 1
self.elasticity = 0.9
class Player(Entity):
"""Player class. Provides all player variables and methods"""
def __init__(self):
RigidBody.__init__(self)
self.grounded = True
self.direction = "Right"
self.axis = "Down"
self.jump_counter = 0
self.image = pygame.image.load('sam_stand.png')
How come self is recognized for all the other attributes for the Player, except for self.image? If I change it to image = pygame.image.load('sam_stand.png') the problem goes away.

RigidBody.__init__(self)you are calling RigidBody's constructor passing it your present object (i.e. an instance of Player).... what is your goal?RigidBody.__init__()method takes positional (required!) arguments!