In Python, variables that are used inside a function are known as local
variables. Before they are used, they must be assigned a value. A
variable that is used before it is assigned a value is assumed to be
defined outside that function; it is known as a global (or sometimes
nonlocal) variable. You cannot assign a value to such a global variable
inside a function without first indicating to Python that this is a
global variable, otherwise you will see an UnboundLocalError.
So, what you need here is the following:
track = True
global track # <-- Add this
track = not track
Note that I wrote
True and not
TRUE and that there are parentheses
() following the name of the function,
coordinates(), when I defined it. You likely had the same in your code (otherwise there would have been some syntax error and/or name error). In general, when asking questions, do not recopy by hand your code, but copy-paste it, adding extra indentation so that it shows properly.