Question concerning quirky global variables

Official forum for open source FreePIE discussion and development.
Post Reply
Jabberwock
Cross Eyed!
Posts: 197
Joined: Mon Mar 02, 2015 3:58 pm

Question concerning quirky global variables

Post by Jabberwock »

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:

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?
Post Reply

Return to “FreePIE”