I'm trying to write a program with Python to emulate an 'old' online game in which you drive a worm through the screen with some inputs from the keyboard.
import turtle # Set screen and background wn = turtle.Screen() wn.title("Turn with Left and Right buttons your keyboard. Click on screen to EXIT.") wn.bgcolor("black") # Snake settings snake = turtle.Turtle() snake.color("purple") snake.shape("circle") snake.shapesize(0.25,0.25) snake.pensize(5) snake.speed(10) t = 0 # Define Go loop, turn Left and Right def go(): t = 0 while t < 1000: snake.forward(1) t += 1 def left(): snake.circle(1,8) go() def right(): snake.circle(1,-8) go() # Inputs and Exit on click wn.onkey(right, "Right") wn.onkeypress(right, "Right") wn.onkey(left, "Left") wn.onkeypress(left, "Left") wn.listen() wn.exitonclick() turtle.done() The problem here is that, after some moves, the program crashes returning:
RecursionError: maximum recursion depth exceeded while calling a Python object. I'm still a beginner so i don't get what I'm doing wrong. How can I fix the error?
leftorrightit was calling thego()function again. Which is essentially what you found when debugging and what your answer eludes to