Is it better to use Object-Oriented-Programming (OOP) when making a 3D platformer or regular functional programming?

This question has been bothering me for the past few days. I’m making a 3D platformer game using OOP, and i’ve made a lot of progress on it, but not to the point where it’s impossible for me to revert back to functional programming. Simply put, the platformer contains collectibles, obstacles, a menu, checkpoints, and a ranking system for how good you do in a level. Is it better to do all of this in OOP or the opposite?

Its incredibly easy to make a mess with OOP in Lua, so as a rule I’d recommend just staying with functional styles. Part of the reason is Lua does not have any built in rules for inheritance and interface specification. So you can write yourself a very complicated system of entities that don’t actually provide you any benefits. If you want to add a light sprinkle of OOP I would highly recommend the concept of Decorators. You can have functions that add capabilities to a table, such as giving an object a response to being hit from below, touched, make it collectable, etc.

Alright, thanks! I still do have another question tho. I can still use ModuleScripts for collectibles and stuff, right? Or do i have to use a for i, v loop that loops through every collectible in the game and gives them functions for example reacting to being touched, spinning around, etc.

Maybe you can take some inspiration from https://devforum.roblox.com/t/new-platformer-template/3088494? I assume you haven’t seen it yet.

Paradigms are good in langugaes they are used in, Luau is mixed paradigm languages that can imitate anything you really want, which is one of the greatest bonuses in Roblox

OOP is paradigm which hides logic behind objects, this mean it can be very good to use, when working with objects

If you need a lot of things with similar propertiess or similar functionality, you should go for OOP, you can also mix it with FP or ECS to make very flexible code


Example

Let’s say you have inventory, data saving, buttons and all of that should be programmed in mixed paradigm, because there are no objects, and even if they are over-abstracted, connecting button to function is better than making entire class to do it

But let’s there are slots in your inventory system, and each slot can hold item and be moved, there will be 100 visible slots at once, this is where OOP shines, because you can manipulate each of those slots with methoods instead of functions you can pretty much save a lot of work for yourself


Conclusion: Use OOP with objects, and consider mixing it with other paradigms

Fun Fact: ECS composition is used in OOP very often, and overall idea of entities is nice, as i said buttons that you can connect to same function are entities, not objects, but this makes them simplier to work with

EDIT: You should also simply utilize module scripts and you’ll be fine with sorting and organizing stuff

If you have a group of something that needs done frequently, like every frame, then keeping track of it in an extra table provides the best performance. If it only needs done once, just make the call when the object is loaded/created or placed.