Danny. Doo
Danny. Doo

Reputation: 1

Python basic pong game, '>' not supported between instances of 'method' and 'int'

I just started python a few days ago as my first programming language, so the problem I bumped into probably isn't a big deal. I'm sorry if it's a simple syntax error. I am building a basic pong game using the turtle module and bumped into a problem making the ball bump off the paddle. When the ball's ycor goes between the paddle's ycor I expect the ball to bump off, but the ball seems to stick to the paddle, and I receive a message saying

Traceback (most recent call last): File "C:\Users\USER-PC\Desktop\Python\Pong game practice.py", line 92, in if ball.xcor() > 330 and (ball.ycor() < paddle_b.ycor() + 50 and ball.ycor > paddle_b.ycor() - 50): TypeError: '>' not supported between instances of 'method' and 'int'

I suppose that the error occured in the following parts.

while True: wn.update()

# Move the ball
ball.setx(ball.xcor() + ball.dx)
ball.sety(ball.ycor() + ball.dy)

# Border checking
if ball.ycor() > 290:
    ball.sety(290)
    ball.dy *= -1

if ball.ycor() < -290:
    ball.sety(-290)
    ball.dy *= -1

if ball.xcor() > 390:
    ball.setx(0)
    ball.dx *= -1

if ball.xcor() < -390:
    ball.setx(0)
    ball.dx *= -1

# Paddle and ball collisions
if ball.xcor() > 330 and (ball.ycor() < paddle_b.ycor() + 50 and ball.ycor > paddle_b.ycor() - 50):
    ball.setx(340)
    ball.dx *= -1

Thank you for any guidance or help.

Upvotes: 0

Views: 350

Answers (1)

Mykola Mostovenko
Mykola Mostovenko

Reputation: 93

The very issue you have is in the next place

ball.ycor > paddle_b.ycor() - 50

ball.ycor is a python method, when paddle_b.ycor() - 50 is an int, that what the interpreter warned you about. You just need to add brackets to actually call the method.

ball.ycor() > paddle_b.ycor() - 50

Upvotes: 2

Related Questions