Can somebody give me some basic stuff I can do with OOP?

Hello everyone!
I am trying to learn OOP, but I am still extremely confused.
Many tutorials I have seen are based on text and is mostly based on printing on things such as age, health, etc. But how is OOP used in actual game logic? Can somebody please give me something basic I can do using OOP that can be used in a game?

In my opinion, OOP is overrated for Roblox. Also, Roblox’s instances are OOP, so think of OOP as the built in methods. (Instance:FindFirstChild() is a method for the class Instance)

I could be biased because I don’t code much in OOP languages such as java or C#.

Development on Roblox is an example of utilising OOP: you are using pre-built classes (scripts, parts and more) to build a game. For example, every item that can be found in the game’s Explorer tab is an example of an object and each of those belong to a class. It can be difficult to find something to invent using classes because of the wide range of tools you already have access to.

The thread below provides a basic introduction for OOP and its implementation in Roblox. It gives the example of creating a car class and some of its attributes - perhaps you could have a crack at that, or try applying these methods to something different entirely (planes, buildings maybe?)

Lua uses metatables which aren’t the most user-friendly introduction to class programming. I personally don’t tend to make my own classes (instead relying on Roblox’s existing classes) and found OOP much more applicable when working with Java, Python or Unity. You’ll be able to find a lot of resources on OOP in those languages.

OOP is extremely useful for game development, that’s why it’s at the very core of the Roblox API. Since Lua is not an OOP language (it can only emulate OOP behavior), implementing OOP in your code might be difficult, but definitely worthwhile in many cases for organization to maintain compact (and readable) code.

3 Likes