Answered by
4 years ago Edited 4 years ago
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:
5 | function Dude.new(message) |
6 | local self = setmetatable ( { } , Dude) |
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.
1 | local speedmask = Dude.new( "B)" ) |
2 | print (Dude.ClassName, speedmask.ClassName) |
4 | 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.
05 | local speedmask = Dude.new( "B)" ) |
06 | local proROBLOXkiller = Dude.new( "colons are overrated" ) |
10 | 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.
1 | function Dude.Speak(person) |
5 | speedmask.Speak(speedmask) |
but that's just weird to write. the colon makes it look nicer :)