This seems like it should be simple but I'm new to python. I'm learning how to use Turtle so I decided to create pong. All the tutorials I found have you using screen.onkeypress but this creates a lag in movement which I couldn't find a fix for, so I instead set the movement direction inside of the onkeypress, and then have a recursive function that runs every 10 milliseconds like this:
def movePaddleB():
if (paddleBDirection != 0):
y = paddleB.ycor()
y += 1 * paddleBDirection * paddleSpeed
paddleB.sety(y)
screen.ontimer(movePaddleB, 10)
movePaddleB()
This seems to work really well, but I want to make the function dynamic so that I don't have to create 2 functions, one for paddle A, and one for paddle B (see code below).
def movePaddle(paddle,direction):
if (direction != 0):
y = paddle.ycor()
y += 1 * direction * paddleSpeed
paddle.sety(y)
#ADD DYNAMIC PARAMS TO RECURSIVE FUNCTION CALL
screen.ontimer(movePaddle(paddle,direction), 10)
movePaddle(paddleA,paddleADirection)
movePaddle(paddleB,paddleBDirection)
When I add parameters to the function called in screen.ontimer, I get this error: RecursionError: maximum recursion depth exceeded in comparison. I'm completely lost so any help would be great, even if I have to do this a completely different way.