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
✓ ANSWER ACCEPTED
Is there a way to create your own method/function etc?
1 answer
✓ Accepted answer
You can create your own metatables emulating this behavior.
Create a ModuleScript, in it write:
local Module = {}
function Module.new(age)
-- Age is an example parameter
-- This new function will return a Module object
-- And this function works as a constructor for this Module object
local self = setmetatable({}, Module)
self._age = age
return self
end
function Module:GetAge()
return self._age
end
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 :)
1 comment
0
Thanks!
This discussion is preserved as it was. New answers, comments, and votes are closed.

5 comments
Would there be any specific things id need to learn before pursuing this
AFAIK, there's no way.
Alr then
Actually its possible, I don't recommend doing, but its possible
Check object oriented programming and metatables