I wrote a framework for the things I do a lot in my game - setting up interfaces, unit testing, and access to a variety of locations for other modules (eg. constants, helper code & template objects).
The way I’m doing it right now is that every service gets a reference to the framework variable, so they have full access to everything. The issue comes about when code inside these services needs to access the framework (as an example, I have a main service for controlling AI; inside that service, I have code for controlling the AI’s character; that code has no reference to the framework).
I’ve been thinking about how best to allow everything to access the framework and come up with two solutions. Either I can pass it around to every module that needs it (so it becomes an extra argument into that module’s constructor), or I can reference it through the global table (_G.Framework).
I’m just wondering, is there any reason why I shouldn’t use _G.Framework for this? It seems like the best option but I’ve heard people say not to use _G in the past, so I want to see if there’s any actuality to that or if it’d be fine to go with that option.
You might find this thread with a similar topic interesting. In spite of the title, the answers pretty much turned into the same discussion you’re looking for.
It would be best to make the Framework with Module Scripts and use require (path.to.Framework), and, if another script starts before the Framework, even for a few microseconds, errors can occur.