Question concerning quirky global variables
Posted: Sat Feb 10, 2018 7:01 am
I know that global variables need to be put in a procedure definition. However, I was under impression that it can be ANY procedure definition, even not used one, so I have a habit of making a vars procedure that holds all global variables. It has been working fine till now, but it seems it is quirky when an update procedure is used. Check the code below:
If it is run, toggleA toggles between 1 and 23, even though the starting condition is run only once (which is evident from the clock function). What is going on here?
Code: Select all
import time;
def vars():
global toggleA
def update():
toggleA = 1
diagnostics.watch(toggleA)
diagnostics.watch('OK')
if starting:
freeTrack.update += update
diagnostics.watch(time.clock())
toggleA = 23
diagnostics.watch(toggleA)
If it is run, toggleA toggles between 1 and 23, even though the starting condition is run only once (which is evident from the clock function). What is going on here?