Hi Everyone!
Does anyone know how to simplify this without changing the original declaration of the method in the module script to use dot notation?
blabla.Event:Connect(function()
myModule:SayHello("World!")
end)
Hi Everyone!
Does anyone know how to simplify this without changing the original declaration of the method in the module script to use dot notation?
blabla.Event:Connect(function()
myModule:SayHello("World!")
end)
myModule:SayHello("World!")
is just shorthand for
myModule.SayHello(myModule, "World!")
You need to pass myModule
as the first argument, as the function would be expecting the module itself as the first argument, when specified using a colon. Typically, you’d only need to use colons when you’re creating OOP-style modules, where a colon would access a new instance created from the original module, and a dot accessing the original module.
If your module is not intended as OOP, you have no need to create functions with a colon; just use a dot.
local myModule = {}
function myModule.SayHello(name)
print(string.format("Hello %s", name))
end
return myModule