Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

What does an OO game look like in Roblox?

Asked by 4 years ago
Edited 4 years ago

So, a while back I've begun learning the concepts of Object-Oriented programming. I've then proceeded to write programs that use classes, but they were still highly procedural. Recently, I've started reading a book about Java, and it gives good examples of how a OO systems look.

However, I've been wondering how exactly would something like that look in Roblox. I know we make classes using ModuleScripts and metatables. But what's the general layout?

For example, let's say I have a simple game where the player clicks Parts for points. Additionally, the player sees a Gui pop up when they hover their mouse over something, and there is a script that throttles how fast they can jump using a cooldown.

I could build something simple using classic Scripts and LocalScripts. The Gui and JumpThrottler LocalScripts would be parented under StarterPlayerScript, and they would have functions bound to events (whether that's .RenderStepped or .JumpRequest or whatever) that execute their functions. In terms of the "click parts for points", assuming there aren't many of these parts, I could simply place a Script with a ClickDetector that fires a BindableEvent every time it is clicked, and then another Script in ServerScriptService would register these events, appoint points and handle data saving.

But... how would this look like with objects? There has to be a Script somewhere as something needs to run, and there could be a class called "ClickPart" or something, which spawns a physical Part with a ClickDetector and provides some sort of interface or something for the main script to work with. Data saving logic would also be wrapped into its own class.

But what about the client? I assume there would be one LocalScript to run everything and the rest of the functionalities would have their own classes. Yet I'm still confused about it. Would these classes expose a "process" function or something which the main LocalScript calls every .RenderStepped? Do these classes run their own events?

How about if I need to make a tool? I've scripted a sword once, using a Script parented to the Tool, and then simply parenting it to the player and letting it do its thing. Would this look somewhat similar with classes? Or would there be a "Sword" class, which when initialized, would create a Tool with the proper handle, give it to the proper player and then handle all the tool logic (activation, equip/unequip, etc.) itself?

Does anyone have any examples? Thanks a ton :D

1 answer

Log in to vote
0
Answered by
Lakodex 711 Moderation Voter
4 years ago
Edited 4 years ago

We do not care about your education (Which is litterly the whole entire thing), and if you've learned java you should've probably learned lua while doing it as java and HTML are really simple as well as lua is, also please don't make things as big as the 2012 dictionary or people do not wanna answer it as its so big that there eyes will start turning in to boiled eggs and will probably pull them out just to eat them, please make it shorter and someone will finally answer with a legit answer.

Ad

Answer this question