I was just wondering if it was possible to actually make your own method/function. For example: I could make my own :GetProperties() thing. I just wanted to know what I should learn to be able to do this. And whether it's actually possible. Thanks in advance
You can create your own metatables emulating this behavior.
Create a ModuleScript, in it write:
01 | local Module = { } |
02 |
03 | function Module.new(age) |
04 | -- Age is an example parameter |
05 | -- This new function will return a Module object |
06 | -- And this function works as a constructor for this Module object |
07 | local self = setmetatable ( { } , Module) |
08 |
09 | self._age = age |
10 |
11 | return self |
12 | end |
13 |
14 | function Module:GetAge() |
15 | return self._age |
16 | end |
17 |
18 | return Module |
:GetAge()
method returns the current value of the _age property of the initialized Module object. As you can see, it uses a colon, which is a shorthand for .GetAge(self)
(note the period instead of a colon). It's basically syntactic sugar.
Remember to accept the answer if is it helpful for you! I'm glad to help :)