In this code:
# other variables defined above
global movex
movex = 0
global movey
movey = 0
def wasd(event):
key = event.char
if key == 'w':
movey = -5
elif key == 'a':
movex = -10
#elif key == 's':
#movey = 10
elif key == 'd':
movex = 10
p.moverect(movex,movey)
tk.bind('<Key>', wasd)
tk.bind('<Key>', wasd)
largetext = Font(size=13)
p = player(sx1=950,sy1=520,sx2=975,sy2=545)
it says error because I referenced the local variables movex
and movey
(in different cases), before defining them. How did this happen if I defined the variables movex
and movey
as global variables?
I also tried not using the global
keyword, but I get the same error.