Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Does roblox allows modules in module?

Asked by 3 years ago

Does roblox allow modules to be able to require other modules? Like...

-- MainModule
local Module 2 = require(###########)
-- Module 2 
local Module 2 = require (###########)

^^^Does this work on roblox and is this allowed in scripts?

1 answer

Log in to vote
2
Answered by
gskw 1046 Moderation Voter
3 years ago
Edited 3 years ago

Yes, ModuleScripts are allowed to require other ModuleScripts. In fact, with more complex games, it is good practice to have sub-dependencies (with a hierarchical structure) rather than a flat structure. So for example, your modules could be like this:

GameModule  
 -> GunModule  
   -> BulletManagerModule  
 -> MapModule  
   -> VotingModule  

One thing that is not allowed is for ModuleScript loading to cause a cycle. That is, a ModuleScript A can't require a ModuleScript B so that it ModuleScript A gets required again before it has returned a value. For example, this is not allowed:

local self_module = require(script)

return {
    self_module = self_module
}

This is because requiring this module would cause the module to get required again infinitely many times.

However, this is allowed:

return {
    get_self_module = function()
        return require(script)
    end
}

The latter is allowed, because the require() can only run after the module has fully loaded (and returned a value).

0
This was somewhat helpful thx. THUNDER_WOW 203 — 3y
Ad

Answer this question