When I write a function while writing a module script, I was curious about the difference between “:” and “:”.
local module = ()
function module.DotFunction()
end
function module:ColonFunction()
end
return module
Both work fine, but I know there is a difference when using module scripts.
local ModuleScript = require(game.ServerScriptService.ModuleScript)
ModuleScript.DotFunction()
ModuleScript:ColonFunction()
Does anyone know anything about this?
The :
operator is a shorthand for module.ColonFunction(module, ...)
, it passes the object that the function has been called from as it’s first argument. Very useful for OOP.
1 Like
So…
“ServerScript”
require(game.ServerScriptService.ModuleScript):Hello()
“ModuleScript”
local module = {}
function module:Hello(arg)
print(arg)
end
return module
the output is “ServerScript”?
When this function is written as:
function module.Hello(object)
print(object)
end
The output will be the module table itself.
{Hello = function 0x.....}
2 Likes
system
(system)
Closed
November 10, 2024, 3:42pm
#5
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.