Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Using colons in function paramaters ?

I see people do stuff like

function SomethingHandler.new(table : Something)

What does the "table : SomeFunctionParamHere" mean? Is it a reminder of what it should be?

example 2: "Vector3 : SomeFunctionParamHere" Any help is appreciated.

1 answer

You sure you didn't ment

table:someFunc()

?? I don't really know what is function SomethingHandler.new(table : Something) But i will explain the first example i have shown.

Basically there are two methods you can call function in a table:

table.Test()

and

table:Test()

: is only (idk if only but probably) used in OOP. Basically : automatically defines 'self' variable. Which means this

function table:Test()
	print(self) -- self is automatically defined, self = table here
end

is same as

function table.Test()
	print(table) -- we did not use . so there is no self, you need to define the table variable instead
end

These are two same functions, they both will do the same thing, first one with : will automatically define self variable which in this case it's the table. Second function uses . so it does not have self defined so instead of self you will have to use the table variable. You might think it has no use.. right but in metatables in Object Oriented Programming (OOP) without it you are lost.

2 comments

0

Late reply, but sorry this is not what I meant.

0

yes mate you meant lua type checking, I will explain when I will be on pc, I did not know about that too before

This discussion is preserved as it was. New answers, comments, and votes are closed.