I have heard a lot about OOP over the past few months and about how it makes managing your classes easier, i even made some datastore and inventory systems with it and it was quite successful and fun to make,
Here is the question,
OOP in obviously a great idea in languages like java or python since it’s already implemented in the language itself but for Lua you need metatables which takes more processing time than just using functions so is it really worth using in LUA specifically? and do successful games even use it? Or is it just something that devs like to use only for learning purposes?
I think that in general, the organization given by using OOP far outweighs any performance concerns. Most things you are making aren’t going to be super performance heavy, and Luau optimizes metatables to make OOP fast. Obviously, it is just a tool, so you shouldn’t use it for everything.
Well, im working on a game where processing time does matter, its a sword fighting game where once the player hits another player it retrieves some information about both players to verify the hit, the information are being retrieved form An OOP module thats why im asking about it, but from what I understood from your reply, OOP Doesn’t cause any noticeable performance issues and is better than using just functions?
Pokemoncraft had a good response, however I have a couple cases where I use it personally because the organizational factor is great:
I’m working on an interior design game and I have an object called a “WallController” which essentially handles cutouts for windows and doors. I can destroy this controller when a wall is deleted, and I create a new WallController every time a wall is created.
I have a camera wrapper that handles custom camera functions, for example, moving the camera by calling a function instead of manually setting the camera’s CFrame with a new position but the same orientation
I have a typewriter module that uses OOP, it’s good to handle skips in dialogue.
I have a couple custom event objects:
First one is a ConditionalEvent object which fires a signal if a condition is met.
Second one is a multi-event which fires a single event if one of several events fire, which acts sort of as a “hub” event. Good for handling multiple device inputs (eg. tapping on a screen, clicking a button, or pressing a key)
So yeah, it does have its uses, it definitely is a great tool when taking organization into account.
And for your concern about performance, no, it doesn’t cause any performance issues as long as you are properly handling objects that should be garbage collected and aren’t causing memory leaks. I don’t think it’s more performant than just using functions, however the organizational factor definitely outweighs this negligible speed difference.