Reputation: 11
How do I make it so that the goto used previously stops executing when I try to execute another? Whenever I click before the turtle stops moving, the turtle will move to the position I want it to but then resume its previous goto commands. Is there a solution to this?
player = turtle.Turtle()
player.speed(1)
def moveturtle(x,y):
player.goto(x,y)
scrn = turtle.Screen()
scrn.delay(50)
player.penup()
scrn.onscreenclick(moveturtle)
scrn.listen()
scrn.mainloop()
https://i.gyazo.com/307b25676791055f9ace9a08f680437c.mp4
Upvotes: 0
Views: 122
Reputation: 11
I guess there is not a way to get it the way I intended it to be. I wanted the user to be able to change the path of the turtle at any time, but instead, I had to make it so that the turtle must complete its previous path before being assigned a new one.
player = turtle.Turtle()
pos1 = player.position()
player.speed(1)
def moveturtle(x,y):
nonlocal pos1
if player.distance(pos1) == 0:
player.goto(x,y)
pos1 = (x,y)
scrn = turtle.Screen()
scrn.delay(50)
player.penup()
scrn.onscreenclick(moveturtle)
scrn.listen()
scrn.mainloop()
Upvotes: 1