✓ Accepted answer
well, that's it :)
you don't need it. in your case, that is. colons are used for something called static methods. these are functions that do the exact same thing, but are applied to different objects. consider this:
local Dude = {}
Dude.ClassName = "Dude"
Dude.__index = Dude
function Dude.new(message)
local self = setmetatable({}, Dude)
self.Message = message
return self
end
do you recognize this code structure? if not, it's a whole other concept you can go down called lua objects. I do not think there is time to explain what a metatable is, so I will write assuming you know what that is. if not, it doesn't really matter. I'll show you what magic this does.
local speedmask = Dude.new("B)")
print(Dude.ClassName, speedmask.ClassName)
print(Dude.Message, speedmask.Message)
anything in Dude is now static. that means anything you create with Dude.new() will have the same stuff that Dude has. INCLUDING colon functions. conversely, anything that you added inside of the Dude.new() function is its own values.
now you might see where I'm getting at. consider what I have here.
function Dude:Speak()
print(self.Message)
end
local speedmask = Dude.new("B)")
local proROBLOXkiller = Dude.new("colons are overrated")
speedmask:Speak()
proROBLOXkiller:Speak()
see how they used the exact same function, but said something different. each self is different depending on which object used it. you can only do that using self. note that it's the exact same thing as this.
function Dude.Speak(person)
print(person.Message)
end
speedmask.Speak(speedmask)
but that's just weird to write. the colon makes it look nicer :)
1 comment
might be a stupid question but you know i just got started on tables and methods