Silly question about the `GameState` class and global variables

Silly question about the `GameState` class and global variables


In the docstring of GameState in the python-algo, it says that the unit types, FILTER, ENCRYPTOR, etc. are attributes of the class.

However in the implementation they are global variables (coming from I don’t know where) which are updated on __init__. When I initialize a GameState class, I can’t access them as attributes.

Is it just me, or is the docstring misleading? If anyone can shed any light on this issue, I would be very grateful.


Not the best pythonist here, but I will try to explain what is going on:

FILTER , ENCRYPTOR , etc. are indeed global variables, and are not class attributes.
They are used in the scope of the class as a helper shortcuts, for readability.

Probably the most confusing part of the code is that all the unit information, name , short name, stats, etc,
are loaded from the config file, after the game starts.
And that is why something you can expect to be a CONSTANT … is actually a global variable, defined on __init__

Quick way around this, is to copy the Initialization of unit shortcuts FILTER , ENCRYPTOR etc, in the init methods of all your custom classes … and pass the config as a param.
That is good for start, but gets ugly pretty fast :slight_smile:

I would suggest you to use what works in the beginning and don’t worry to much for the architecture,
and at some point, when you feel comfortable, just rewrite the whole thing from scratch