Hello devs,
I’m wondering whether can I create a successful game without using OOP, as I’m struggling with learning OOP as an intermediate coding learner.
Looking forward for replies!
Hello devs,
I’m wondering whether can I create a successful game without using OOP, as I’m struggling with learning OOP as an intermediate coding learner.
Looking forward for replies!
Absolutely.
OOP is just one type of programming paradigm which helps shape your code base.
In some ways it may be easier to use it, and in others, you may find it unnecessary, it all depends on what you are trying to achieve with your game. However, you don’t have to use OOP at all if you aren’t comfortable with it.
What is it that you are struggling with understanding in terms of OOP?
OOP is not necessary. It just makes your code cleaner/more organized, nothing else.
It’s up to you, you can make your code clean without using OOP at all.
For what I know about OOP, I think using normal code without using OOP would be more straightforward
Each programming paradigm is a mindset. Syncing with that mindset can be difficult, and it can be difficult to see the benefits until you aquire the mindset.
For me, OOP is a way to greatly reduce the number of times I write the same code. It also helps my functions have access to many parameters without having to explicitly write
function a(parameter1, 2, 3, 4, 5, 6, 7)
end
a(12344567838392929aaa)
because i can just write
function thing:a()
self.anyParameterIWantWhichHasBeenAddedToTheObjectElseWhere
end
It is most useful to me when many functions need the same parameters. It also means, if i decide a function needs access to another object variable, i dont need to change the () to add the new parametee because i can just write self.otherVariable.
But it is not necessary and there are other methods. Some situations benefit from it more than others.
It is useful to at least know how it works however, because often in large projects you may rely on open-source modules like FastCast for weapons etc. Many open source resources use OOP and while you dont need to know OOP to use them, it can make it easier to understand how they work and add new functionality.
For lua, i just see OOP as making a table (object) that is ‘linked’ to another table (class)
tables can store functions or values. the object usually has values. the class usually has functions (methods).
if you try to find something in the object table that it doesn’t have (like try to find a method it doesn’t have) then it searches the class table for it.
An example of where it may be useful:
I made a User class and gave it useful methods.
Now if I have a player, I can use user = User.getUser(player) to get its associated user object
then i can do useful things:
user:getChar()
user:getHum()
user:getData()
user:loadData()
user:saveData()
user:getState() --(maybe i want to check if the user is busy performing an action so i don't interrupt it with a new action)
user:setState()
local id = user.player.UserId