I’ve always wanted to understand meta tables but no matter how many articles i read or videos i watch, i never understand, i just keep getting more and more confused.
I have no scripts to show because i don’t understand it at all to make anything.
I understand tables/dictionaries, are meta tables similar?
And what can a meta table do that tables and dictionaries not do?
They are used in OOP (Object Oriented Programming), where you focus on using objects and classes to perform operations. For example, you might want to create a class to manage your game GUI so you spend less time trying to do everything manually by providing a class to do it automatically.
Metatables are supplements to arrays and dictionaries (and all other types!). The only difference from any object with and without a metatable is that objects with a metatable may behave differently than those without.
CFrame, Vector3, and even strings all have metatables as well, although getmetatable(...) for any of them is “This metatable is locked.” (debug.getmetatable(…) exists on regular Lua)
It makes things like ("hello"):rep(20) possible ({__index = string}) and myCFrame + otherCFrame too.
You can add these same functionalities to your own custom classes to allow them to do things tables normally wouldn’t, like inheriting functions (without placing them directly inside of the table); adding, subtracting, dividing, etc your objects (with a custom Quaternion, Matrix, or Money class for example); and even make them print or appear in a different way when used in tostring(...). This guide will explain the purposes of each attribute you can use when creating a metatable (which is a dictionary).
A metatable is not a type of table. Tables do not have the property of being a metatable. It’s just that you can assign a table a metatable via setmetatable(x, m).