Hello, I am currently in the development stages of a tycoon game based around the SCP genre and I’d like to share some core functionality and get the community’s thoughts and opinions. My code base is entirely around _G. now after some digging, I’ve found it to be no different from requiring modules, however, many people have different opinions about the use of _G…
Here is an example of a _G. class created on the server, to act as a custom singleton to access all of my most used functions.
_G.Architect = {}
_G.Architect.Services = {
["Workspace"] = game:GetService("Workspace");
["workspace"] = game:GetService("Workspace");
["Lighting"] = game:GetService("Lighting");
["ServerStorage"] = game:GetService("ServerStorage");
["ReplicatedStorage"] = game:GetService("ReplicatedStorage");
["Players"] = game:GetService("Players");
["Chat"] = game:GetService("Chat");
["CollectionService"] = game:GetService("CollectionService");
["RunService"] = game:GetService("RunService");
["Run Service"] = game:GetService("RunService");
["ServerScriptService"] = game:GetService("ServerScriptService");
["HttpService"] = game:GetService("HttpService");
["DataStoreService"] = game:GetService("DataStoreService");
["DataStore"] = game:GetService("DataStoreService");
["ScriptContext"] = game:GetService("ScriptContext");
["TweenService"] = game:GetService("TweenService");
["TS"] = game:GetService("TweenService");
["SSS"] = game:GetService("ServerScriptService");
["MPS"] = game:GetService("MarketplaceService");
["MarketPlaceService"] = game:GetService("MarketplaceService");
["Debris"] = game:GetService("Debris");
["Teams"] = game:GetService("Teams");
["PathfindingService"] = game:GetService("PathfindingService");
["PFS"] = game:GetService("PathfindingService");
["PhysicsService"] = game:GetService("PhysicsService");
}
_G.DataStoreVersion = 3
function _G.Architect:GetService(s)
return ModuleLoad(s)
end
function _G.Architect:SendSnackBar(plr,txt)
_G.Architect:SendClient(plr,"SnackBar",txt)
end
function _G.Architect:SendClient(plr,...)
game.ReplicatedStorage.Remotes.Post:FireClient(plr,...)
end
It’s important to note that _G. is static, unchanging, and is declared at the start once.
I have no noticed any performance issues related to this use of _G. however, I’d like anyone’s opinions or criticisms about the use of _G., how it may be improved, and some issues I may encounter on the way?
Using _G. makes my code easier to expand, debug, and overall organize. I, however, do not want to be building myself a trap to fall into, with memory leaks, and etc.
Thanks