Topic was automatically imported from the old Question2Answer platform.
Asked By
Vaanaattori
Is it good practice to have multiple “global” scripts like say one for the player, one for enemies and so on or would it be better to have one global script where I just organize everything?
Are you storing code or variables in the global script?
Entity2020 studios | 2023-06-21 15:16
Atm my “stat” scripts are variables and i have one global script that has my code
There is a better option to keep static data. Class scripts. If You want to have organized archives of data, containing variables, that are base of calculations, but are not modified by themselves, You can just introduce them as const in class script of any of your objects. This is espiecially useful for things like base statistics, statictics grow per level, damage per strenght stat and so on. This way of containment lets You adjust balance of whole game by tweaking constant variables in class scripts.
I also like to have another “global” class script, that collects even wider constant data, like for example default animation time, max level of characters, debug mode on and off, colors of UI in multiplayer, color saturation reduction of tilemap and so on. I believe it is generally better to collect data in singular script, over in individual classes. Single global class will never be prone to cyclic_dependance problem, which occures when parent wants to check constant of its inheritant.
Accessing class script is easier than accesing autoloded script, and it can’t get overloaded. The only advantage of global autoload is that You can change its variables in-game. But usually You will need 100 times more static variables than dynamic ones.