Lots of programmers say OOP is the best when it comes to scripting, but Modules are just easier and only need to be called once making them more efficient. When programmers argue that OOP is better they say something like “Oh you can use a class system for your code” but Modules are pretty much the same thing and easier to use. I also have not seen anyone give an example of why I should use OOP over Modules.
It’s not a good idea to create objects for everything. Even in object oriented languages like C#, it’s possible to create static classes that can’t be instantiated (you can’t create objects of such classes). Static classes are similar to a Roblox modulescript that returns a table that contains functions and maybe other data but no constructor functions.
An example of how OOP can be useful is creating custom events. If you have an event class, you can just create an event object every time you need a custom event. You could alternatively just use a BindableEvent instead of a custom event but a BindableEvent is an object too although you wouldn’t be the one creating the class.
Of course, you can alternatively write methods like addListener and notifyListeners to modules instead of using an event class. However, using an event class makes it easy to reuse the logic in multiple module scripts or scripts.
In general, OOP is useful when you need multiple similar things that have a state. For example, players in the same server have different amounts of health and one may be jumping or falling while another one is walking so each of them has their own humanoid object containing the health and other things about the state of that spesific player’s character.
Yep. No single paradigm is superior or the solution to everything. It’s just another asset in your arsenal to use when applicable. Unfortunately OOP is insanely over and misused.
Here’s a real example:
I’ve got a round-based survival game I’m developing. It’s based on Plates of Fate, so the main mechanic is that players are floating in the void on their “plate” (a platform), and there are multiple different types of plates. By writing a plate class, and creating all plate types as an object of the plate class, it allows me to have consistent methods I can call on them, and a sort of “framework” to create new types because of how that’s set up. It’s essentially easy enough to where a non-programmer would be able to make new types
all custom classes use module scripts because module scripts are the only way it can be accessed from other scripts, but not all module scripts use OOP. you cant say they are the same thing.
I’m curious about this, can you show how constructing a plate works versus how a module script without OOP constructs a plate? I’ve always seen examples by others but I haven’t had a solid understanding to it, which makes me avoid OOP on Roblox.
Exactly, that’s why you can’t compare which is better because OOP is used in module scripts, and OOP can also be used regardless what type of script it is (since they just use metatables).
OOP is obsolete in scripts other than module scripts because then what would be the point? Unless your game only uses 1 script you aren’t going to be using OOP is a server script.
THAT is why you can’t compare. The guy is asking if he should use OOP over modules, and you inherently cannot compare between these two because it’s obselete in a non-modular script - OOP and modules are meant to be used together.