Lua auto complete doesn’t seem to detect sub modules. I am writing a pretty hefty module, and want to split my class into sub sections for easier readability and to keep things independent. Below is an example script I’m using to illustrate my issue.
Setup:
Script
local DIALOGUE = require(script.DialogueModule)
local CONTROLLER = DIALOGUE:CreateController(workspace.Dummy)
CONTROLLER:Speak("hello") -- autocomplete works
CONTROLLER:Whisper(workspace.Dummy2, "I am whispering to you") -- this will work at runtime
CONTROLLER:Scream("I am screaming") -- this will work at runtime
DialogueModule
local module = {}
local subModules = {
WhisperModule = require(script.WhisperModule),
ScreamModule = require(script.ScreamModule),
}
function module:CreateController(sourceModel)
-- create a dialogue controller for use in other scripts
local CONTROLLER = {}
CONTROLLER.Source = sourceModel
function CONTROLLER:Speak(text)
print(tostring(sourceModel)..":", text)
end
function CONTROLLER:Reset()
print(sourceModel, "states have been resetted")
end
for _,v in pairs(subModules) do
v:Expand(CONTROLLER)
end
return CONTROLLER
end
return module
WhisperModule
local module = {}
function module:Expand(CONTROLLER)
function CONTROLLER:Whisper(targetModel, text)
print(tostring(CONTROLLER.Source), "whispers to", tostring(targetModel)..":", text)
end
end
return module
ScreamModule
local module = {}
function module:Expand(CONTROLLER)
function CONTROLLER:Scream(text)
print(
CONTROLLER:Speak( -- piggyback off of the speak function
string.upper(text)
)
)
end
end
return module
Inside “Script”, the auto complete only shows methods defined within DialogueModule and not the WhisperModule and ScreamModule expansions.
This code will execute and output without any errors.
Dummy: hello - DialogueModule:15
Dummy whispers to Dummy2: I am whispering to you - WhisperModule:5
Dummy: I AM SCREAMING - DialogueModule:15 - ScreamModule:5
This setup is great for a class builder that builds tailored controllers for different applications (if the NPC only needs to use :Speak(), we can disable the expansions and keep the object light, otherwise, we use only the expansions we need). The only drawback is that auto complete will not recognize the expansion.
Is there a way for me to have the autocomplete detect the expansions? Should I just ditch expansions and just merge everything into one super massive and unwieldy script? Is there a better way to set everything up that has autocomplete support?