[Solved] Code does not work in Python with turtle module [closed]


When you initialize your variables playerX and playerY you don’t specify they are global, so the function is trying to set the value of a local variable that does not exist.

To fix this at the beginning of your update_coords function add global playerX, playerY

This tells the computer that playerX and playerY are the global variables you created earlier.

The new function would look like this:

def update_coords():
  global playerX, playerY
  playerX = tank.xcor()
  playerY = tank.ycor()
  playerHeading = tank.heading()

solved Code does not work in Python with turtle module [closed]