Advanced Module Loader
Check out my Other posts:
CutsceneManager - Manage/Creates cutscene of qualtiy
What is Advanced Module Loader?
Advanced Module Loader, or AML is a module loader which is capable of:
Requiring module in a better way
Calling a startup function
Spawning threads more optimizable
Shutting down the server if any server modules failed to load
Why use a module loader?
A module loader is used for advanced modular frameworks which only uses modules. Of course you don’t have to have a modular framework, but personally it looks more organised than using a lot normal scripts
Example code:
--// EXAMPLE CODE
--// By @rugg3344
local AdvancedModuleLoader = require(script.AdvancedModuleLoader) --// Set this to the location of the module
local modules = script.Parent.Modules --// Set this to the location of your modules container
--// Initializes the main method
AdvancedModuleLoader.process(
modules, --// The folder that contains all the modules
2, --// How deep you want the search to go
"initialize" --// The name of the function that will initialize the modules
)
Methods:
Methods
require:
Requires all the modules in the specified array and returns them
[Params]: modules: { ModuleScript }
[Returns]: { any }
Script:
local requiredModules = AdvancedModuleLoader.require(array)
glob:
Digs into the folder specified and digs as far in as the depth is set.
Note: if depth is set to math.huge
, then it will dig as far as it goes
[Params]: modules: Folder, depth: Number
[Returns]: { ModuleScripts }
Script:
local array = AdvancedModuleLoader.glob(
modules,
math.huge
)
local requiredModules = AdvancedModuleLoader.require(array)
process:
Uses AdvancedModuleLoader.glob
a sup AdvancedModuleLoader.require
to load them. Afterwards it will do a startup function with a set name
Note: callFunction
is the name of the startup function!
[Params]: modules: Folder, depth: Number, callFunction: string
[Returns]: nil
Script:
AdvancedModuleLoader.process(
modules,
2,
"initialize"
)
Settings:
Settings
kickWhenError:
Enables/Disables shutdown when the servermodules does not require every module correctly
Value: boolean