A : is used for method access of an object. To see what this means I’ll lay out a hypothetical Vector3 definition:
local Vector3 = {}
Vector3.__index = Vector3
function Vector3.new(x, y, z)
local new = {}
new.X = x
new.Y = y
new.Z = z
return setmetatable(new, Vector3)
end
function Vector3:Dot(other)
return self.X * other.X + self.Y * other.Y + self.Z * other.Z
end
The use of the : in the Dot definition injects the self variable into the code for you to use. An equivalent definition could be
function Vector3.Dot(self, other)
return self.X * other.X + self.Y * other.Y + self.Z * other.Z
end
Similarly you can access the Dot function either using “:” or “.”
local vector = Vector3.new()
local other = Vector3.new()
-- Using . to access Dot
vector.Dot(vector, other)
-- Using : to access Dot
vector:Dot(other)
This Isn’t exactly what I was talking about. I know about the difference between colons and dots.
My question was Vector3.new() returning a vector3 and Vector3.new():Function()
E.G: Vector3.new():Lerp() or Vector3.new():Dot().
My only idea, which doesn’t work, is returning a table of functions like:
local T = {}
function T:Something()
-- Do stuff
end
return T
However that does just that. Returns a table. If i wanted to get something using .new on one of my functions, it would return that.
That’s the issue. I want to return the value if you don’t use any : or . on it. And return a list of functions If I do call on it like that.