Modules exist to easily change code for scripts that require it, at least thats as much as I know.
I am just getting into modules, simply because I want to be able to update code easily for scripts I will be using extensively.
I want to be able to have a function, and within that function have the ability to call other functions in the module script.
I don’t think this is how module scripts work, but I need to be able to easily update code, but not be limited to just one function and nothing else.
I had tried variables in the script that requires the module, but like I said before, I don’t think it works that way.
Basically, a proper script that has the ability to call other functions within said script, and store global variables, but acts like a module script so I can easily update code for all scripts that require it.
I’m not sure I understand the question, are you asking whether modules can call functions within themselves? If so, then yes:
local module = {}
function module:function1()
self:function2() -- or you could type module:function2()
end
function module:function2()
print("Second function")
end
return module
The purpose of module scripts isn’t simply to “easily change code”, modules are the key to writing code cleanly and clearly though Object Oriented Programming. I’d recommend reading this tutorial: All about Object Oriented Programming
local module = {}
local val = 0
function module:increment()
val = (val + 1)
end
function module:decrement()
val = (val - 1)
end
function module:getVal()
return val
end
return module
local module = {}
function calculateNumber()
return 2+2
end
function module.getNumber()
local calculatedNumber = calculateNumber()
local newNumber = calculatedNumber + 5
return newNumber
end
return module
A module works exactly how a local script would, except if you want to call functions outside of the module you’d have to call them “module.BLABLABLA” inside the module and run them like “requiredModule.BLABLABLA()” in a localscript.