1. The Situation:
I’m working on a big game that has many scripts, using studio script sync^. To make life even more complicated, the game/experience features multiple places. There is overlap in the scripts between these two places, but it is not total, i.e.
Place 1 requires script packages A, B;
Place 2 requires script packages B, C;
Thus, to make maintenance/development of these packages not a nightmare, I have structured my game directories similarly to:
ReplicatedStorage.A.Scripts.BlaBla.ModuleScriptXYZ
ReplicatedStorage.B.Scripts.BlaBla.ModuleScriptBNM
ServerScriptService.A.BlaBla.ModuleScriptIOP
ServerScriptService.B.BlaBla.ModuleScriptTYU
“Place 2” in the above example would then have “root folders” B and C, instead of A and B.
2. The Issue:
This then means that in all of my scripts, I need to explicitly find each module script I want to reference, i.e. fully qualify my module scripts:
-- Generic script:
local ModuleScriptXYZ = require(game.ReplicatedStorage.A.Scripts.BlaBla.ModuleScriptXYZ)
-- ... and so on, for MANY modules...
This becomes extremely unwieldy, especially when I needed to move literally every script in my game to conform with the A/B/C foldering style so that I can script sync more intelligently.
You can imagine how painful that was - thankfully vibe coding tools made this much easier (but still miserable).
(Understand that this game was originally written way before script sync was a thing, and rojo was still a pretty fledgling tech).
3. The Solutions I’ve Tried:
To get around this, I built a module script that, upon first load, reads through the whole game directory and caches a dictionary that maps module/script names to their instances.
Consumers can then find scripts via
ScriptRegistry.GetModuleScript("ModuleScriptXYZ")
and, in runtime, it works! Lua magic, yay!
The problem here, though, is that this breaks Intellisense! Since static analysis can return in the best case a generic “ModuleScript” type (as the exact module types are determined at runtime), I lose any information on what methods the module contains, and indeed can’t “find definition” of methods that I essentially am guessing exist. This is not ideal, and frankly I am now leaning towards going back to fully qualified declarations (i.e. ReplicatedStorage.A.Scripts.BlaBla…)
In OOP-land, there would be several strategies to deal with this scenario (Dependency Injection my beloved, or just type-casting to the expected module types), but I can’t seem to figure out any Luau ways to accomplish this (as, of course, modules are not true class types but rather just spicy tables).
4. The question:
How are y’all handling this problem?
Are you using fully qualified declarations, or some other strategy?
I’ve tried googling, searching the dev forum, chatGPT’ing, Claude’ing, and I’m kind of at wit’s end here.
I guess a last resort would be to, like, fully qualify all the scripts by hand in my “Script registry” module and then have a getter for each module, but I suspect that also wouldn’t work too well, and would obviously suck to maintain.
Though to be honest, maybe that would still be an improvement.
Thanks for reading!