Reputation: 398
I am trying to create a simple object-oriented pong game. I have a Player
object and one method (create_paddle
). When I create an instance of Player
and call the create_paddle
method it gives me the following error:
Traceback (most recent call last):
File "C:\Users\jerem\Documents\python_programs\pong.py", line 30, in <module>
player1.create_paddle(30, 180, 15, 120)
TypeError: create_paddle() missing 1 required positional argument: 'h'
Program:
class Player:
def create_paddle(self, x, y, w, h):
pygame.draw.rect(surface, white, (x, y, w, h))
player1 = Player
player1.create_paddle(30, 180, 15, 120)
I have looked up the error and no other posts helped. Any help is appreciated! Thanks, JC
Upvotes: 0
Views: 7760
Reputation: 9624
You're missing parentheses when creating the object:
player1 = Player()
Which means you're just assigning player1 to Player and trying to call your method like a static method....so self isn't getting passed for you.
player1.create_paddle(player1, 30, 180, 15, 120)
That is what python does for you behind the scenes.
Upvotes: 8