I'm confused. What is different about player1_head
compared to the other variables I am printing in the code below? As far as I can tell it should behave the same as the others - it's declared in the global scope, no? I don't think it's a typo.
UnboundLocalError: local variable 'player1_head' referenced before assignment
from turtle import *
from random import randint
from utils import square, vector
player1_xy = vector(-100, 0)
player1_aim = vector(4, 0)
player1_body = []
player1_head = "It looks like I'm assigning here."
def draw():
"Advance player and draw game."
print("xy: ", player1_xy)
print("head: ", player1_head)
print("body: ", player1_body)
player1_xy.move(player1_aim)
player1_head = player1_xy.copy()
player1_body.append(player1_head)
square(player1_xy.x, player1_xy.y, 3, 'red')
update()
ontimer(draw, 200)
setup(420, 420, 370, 0)
hideturtle()
tracer(False)
draw()
done()