Can a module script in any way use a recursive function?
for example
function module.EditAllParts(Parts, Transparency, Color, Visible) ... EditAllParts(v, Transparency) ... end
Will create an error message, "Unknown global EditAllParts" Any way around this?
Yes, and I used this to create a GetDescendants module.
Think of it this way: Every variable that you create in a script is stored in a table called the environment. The environment in your script:
{ module = { function EditAllParts(arguments) --lots of stuff end } }
So, you can't just access the function directly, as the function isn't a direct member of the environment. Much like you can't access a part like game.Part
. You have to access the module first, then call EditAllParts from there.
function module.EditAllParts(Parts, Transparency, Color, Visible) --stuff module.EditAllParts(v, Transparency) --Remember the module --more stuff end
Another option is to define your function normally:
function myWhatever(n) myWhatever(n - 1) end
and then just export that function:
local module = { myWhatever = myWhatever } return module -- or, simply `return myWhatever` --------- local r = require(modulescript) r.myWhatever(10)