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

Is there a way to create your own method/function etc?

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

5 comments

0

Would there be any specific things id need to learn before pursuing this

0

AFAIK, there's no way.

0

Alr then

0

Actually its possible, I don't recommend doing, but its possible

0

Check object oriented programming and metatables

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.