I recently picked up metatables and metamethods, now I’m wondering in what circumstances should you use OOP. Should you have a mix of OOP and normal or does it depend on the type of your game?
Roblox itself functions almost exclusively on OOP, except very subtly.
Let’s have a look at some features of OOP: classes and attributes.
Each object you insert into the game has various properties attached to it, a BasePart has a CFrame as well as BrickColor. We treat these primarily as properties, but what do we use when we want to listen to one change? We use the “AttributeChanged” method - which means they’re fundamentally objects.
One of these properties/attributes is “ClassName”, which can in turn be interpreted as “which class does this object belong to”.
These objects even have their own methods, BasePart objects have the “Touched” and “TouchEnded” method attached to them.
So if you’re looking at this from a computer science point of view, it is much harder to not use OOP in your games than it is to use it. If you don’t want to use OOP you’ve got to create your own scopes and variables and manipulate them through threads - however remember that all global variables can be accessed through referencing the script object so fundamentally even variables we create in scripts are defined as attributes of the script object we think we’re editing.
I understand this is all a bit deep, and they in no way rely on metamethods and metatables (which are very different things that in fundamental terms do not relate to standard OOP methods brought to us from an academic point of view).
Thank you for the point-out. I have recategorised this thread.
The Discussion category should be left for talking about the art of development on Roblox. Scripting Support is as much a valid venue for this kind of question as it is for getting specific help on problem assets in your game that you want to fix or learn how to construct.