Simple variable question

Hello again, it’s agoose77.
I have yet another simple python question.
How do you define and change global variables (variables that won’t be redefined when running the class multiple times)
i tried using

global var
class test():
     def other():
         var = eight

but ran into many problems.

NB - here is the script in case anyone can offer further help
It’s designed for Moguri’s component system but apart from that is the same format as usual bge python.

Why not just use a file?

Because it’s too slow, i need to define gobal variables, but it’s failing.

anyone??thanks!

First result from googling ‘python global variables’:

Before assuming i am absolutely appalling at using the internet, i would like to say that i have tried that and have had problems :frowning:
The main issue is getting the script to execute multiple times

If I remember correctly the global should go inside to the def or else the def will create its own variable called var and not use you existent var global variable. It all has to do with the scope of the variable, python has inserted those rules to eliminate the global variable problem where names clash and before you know your programm start acting all crazy because you made a mistake that will be impossible to spot later. Those rules might seem annoying now, but will save you tons of debuging hours later by forcing you to use good programming practices.

The general attitude with global variables, is , dont use them.

If you look for easy route, best way is to use a class and create your variables in there. Then it will be dead easy to access your variables by classname.variablename syntax. This way you wont have to worry about scope or anything. Classes rock by the way, making code extremely easy to read and debug, highly recommend them , even for tiny porgramms.