I have seen these functions with “:” in ModuleScripts:
local part = {}
function part:Initiate()
end
return part
What does the “:” do?
I have seen these functions with “:” in ModuleScripts:
local part = {}
function part:Initiate()
end
return part
What does the “:” do?
It allows you to use self
ex:
local part = {}
part.mydata = 1
function part:Stuff()
print(self.mydata) -- 1
end
function part.Stuff2()
print(self.mydata) -- nil
end
return part
self is used in OOP (Object Oriented Programming) in metatables.
If a function has a colon operator and you want to call it with the dot operator, do this:
myObject.myFunction(myObject)
which is equivalent to:
myObject:myFunction()
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.