say that you were currently writing a script called “EggHandler” and so in that is the logic for hatchiing an egg, you then use ur pet class to create the pet after they hatched it by saying local pet = pet.new(), on your pet class you have a upgrade method but we dont need to use that yet, a few minutes later you’re now writing a script called “UpgratePetHandler” which handles all the gui and stuff for upgrading the pet, how would you use your pet class’ upgrade method?? in a summary, all i’m asking is how are classes useful when you’re using multiple scripts to do different stuff
I find it useful for implementing a constructor class
bump [charminimumahahafwrwwda]
It is useful for creating complex data structures and managing each one of them independently. It’s also easier to maintain object-oriented code compared to other coding paradigms (imperative, functional, etc.) It also uses abstraction efficiently to separate an object from its internal implementation.
Also you probably shouldn’t bump your topic since you only made it 30 minutes ago.
Well, I barely understood that, but you don’t need an upgrade method for egg hatching, as that script is only made for hatching eggs, so there is no point in creating an upgrade method in a module that hatches eggs.
It would make more sense to put the upgrade method inside the “UpgradePetHandler” rather than the “EggHandler”.
Anyways onto this:
Classes help organise the code in a more simpler fashion, because you can create multiple objects that can interact with different scripts, and you don’t have to duplicate logic to modify them.
In summary, it just keeps the game cleaner, modular and easier to maintain. Because you don’t have to duplicate a ton of logic to modify some properties.
Did that answer your question?
OOP is used to create new types with allowed states and operations. If you just grouped a set of variables, then any combination of values is possible, and that might not accurately reflect meaningful states for that set to be in. An object has functions which you design to only allow valid operations. I.e. only those functions should touch the set of variables inside the object.