Global Boolean Variant

OrionVeteran

Deity
Joined
Dec 25, 2003
Messages
2,443
Location
Newport News VA
I hope this is an easy one. I want to call and change the value of a Global Boolean Variant from any function from any .py file. Let's say I have a Global variant:

Global MyReferenceVariant
MyReferenceVariant = True

I can refer to this in any function within the current .py file but making a call from functions within other .py files, does not seem to work.

My question is: How can I refer to MyReferenceVariant from another .py file?

Respectfully,

Orion Veteran :cool:
 
Let's say you have a file called OrionsGlobals.py which contains the following:
Code:
Alpha = True
Beta = False
Gamma = 12

To reference those variables in another file you would do stuff like this:
Code:
import OrionsGlobals
if OrionsGlobals.Alpha or OrionsGlobals.Beta:
	# do some stuff

if OrionsGlobals.Gamma < 10:
	# do some other stuff
 
Let's say you have a file called OrionsGlobals.py which contains the following:
Code:
Alpha = True
Beta = False
Gamma = 12

To reference those variables in another file you would do stuff like this:
Code:
import OrionsGlobals
if OrionsGlobals.Alpha or OrionsGlobals.Beta:
	# do some stuff

if OrionsGlobals.Gamma < 10:
	# do some other stuff

I think I messed up in trying to indicate what I really need. How do I change the value of OrionsGlobals.Alpha from True to False from the other file?
 
Code:
OrionsGlobals.Alpha = False
Yeah, it's that simple. However, if you are going to do this, it's usually better to have OrionsGlobals provide getWHATEVER() and setWHATEVER() functions for access rather than accessing them directly like that. Either module-level functions (e.g. OrionsGlobals.setAlpha(False) or OrionsGlobals.setBoolean("Alpha", False) or provide a class of global variables that does a similar thing.
 
Top Bottom