So I just finished (basically) making a OOP Combat system, this is actually my first time making one and I plan to add many more features, you can customize the amount of damage or whatever, anyways here is the system, also this is my first OOP Combat system, I plan on adding animations and stuff like that more features too!
Where the code is ran!
local CombatRemote = game.ReplicatedStorage.Combat
local CombatClass = require(game.ReplicatedStorage.CombatClass)
CombatRemote.OnServerEvent:Connect(function(plr)
local char = plr.Character
local hurmp = char:WaitForChild("HumanoidRootPart")
local Hit = CombatClass:Hit(15,hurmp) -- Damage is 15
Hit:DoDamage() -- Custom Damage Function does all the work in the backround!
end)
So this very loosely fits the definition of OOP, and I don’t it fits the definition because you meant it to be.
OOP at its simplest is just a data structure with functions and/or data. So technically if you consider the module CombatClass to be an object then it does have methods associated with it and does fall under the definition of OOP. However most people would consider your module to be a function dump rather than an OOP module because all of the function within it are static.
Doesn’t seem very Class-like. Usually you’d use a constructor (such as .new on Roblox classes) to create an entity or instance of the class, which is then treated as an object of the class (hence object-oriented).
This just seems like a module where you’re using : instead of . notation. That doesn’t make it OOP, it just makes it organised code.
Here is some of the backend of my code, for uh better understanding?
Anyways using my method I can make more functions that inherit the traits of this said constructor, people have been telling me Im doing it wrong but my methods inherits traits and uses Polymorphism, Encapsulation and Inhertiance/Composition
I see. That’s certainly an interesting way to do it. I think the use of Hit as the constructor, using colon notation before it was an object and the fact your object only lasts for a short period made it hard to read. In terms of initial feedback, readability is certainly a big one.
The rest of my feedback is that this still doesn’t feel very OOP-like. You define the functions with every object creation, instead of as a base class that gets inherited by the object using metatables and metamethods. It feels quite clunky and sort of removes all the elegance and benefits of OOP if you can’t access the object outside of that connection and if the functions are defined again and again and again instead of just defining them once in a single bit of memory.
My methods uses Polymorphism, Encapsulation and Inheritance/Composition, and I think it’s still Object Oriented.
I made a object oriented mission system recently and I have a base mission “constructor”, and I can expand it out, so I decided to make a sub constuctor that has it’s own methods/functions that is called AdvanceMission, and this one holds a variable for a specific enemy.
If I try to get the “GetMainEnemy” method, from the Default Mission constructor, it wont show up because it isnt apart of the methods ive provided it.
If I try even further to print out the enemy, using this method that the default mission constructor doesnt have, you guessed it, it’ll error
That example shows my method using inheritance, which is one of the key features of the Object Oriented Paradigm. I won’t go on to show Encapsulation or Polymorphism because you and I both know it’s there, so no need to explain it
Okay, I’ll happily back down and just boil it down to preference. It just feels wrong to me to define the exact same bit of code in a new bit of memory every time you create an object instead of just using a metatable and defining the functions in a class table once.
I think the readability is still a bit of an issue, but again, possibly a preference thing. I notice your semicolons on each line so I assume you just have a particular way of writing code that you like to stick with.
When I write code for others to look at I try to make the function names as obvious as possible. I think you did that well for the functions defined inside each object, but possibly not for the constructors. Terms like new, create, load, and connect are good examples that describe what they do. You’ll find these on almost all Roblox constructors that create something.
In terms of the system there isn’t much else to comment really. I think the feedback will all just be code style and code related as the system itself does what it says and just simply gives damage to those NPCs. The magic is only in the code and if the code works then it’s just housekeeping and making it as flexible as possible. I’ve given my feedback on both of those.