Object Oriented Programming help

Hello, I am currently struggling with server/client communication while using OOP.
Let’s say I want to create an ore object that you can mine. I want to handle input and increment player stats on server. I could easily script such system without using OOP, I’m just trying to figure out how to do it with OOP since I want my code organized and structured properly. How would I connect client and server while maintaining organization and security?

Any help is appreciated! Thanks!

Metatables don’t get passed through remotes so you need a way of “wrapping” objects to identify what metatable they need once received. I have done this and it works well. Stay away from inheritance if you can, most of the time you don’t need it. Write down what object types have what methods and fields, and try to keep them all defined in their own file, or it becomes a pain to figure out what type on object is.

With server and client you will have to just accept the fact that you cannot have the advantages of OOP which is encapsulation where you only have 1 object and all the nice functions attached to it.

You will no doubt have to split your object into 2 one for server and client. However to organize it you can focus on using components to split the functionality between server and client given the same object.

For example for your ore on the client you can create an object that is ore which has an input component and a network component and the ore object on the server has a data component along with the shared network component.

Object on the client triggers input → sends data to server to trigger for that instance → server gets its own copy of the object with the same instance ID and does its own thing with its own special player stats component.

My favorite quote: Can’t fit round pegs in square holes.

What I described is sort of like ECS worth taking a look but I’m not a computer science guy. There might be a better way I would also be curious to know as well.

There are no ways to serialize functions or metatables, meaning that they will never replicate.
The OOP term in Luau is very wide; there are 3~ OOP methods:
Metatable OOP,C like OOP (function reference/pointer), and, well, closures.
You can send only necessary data and bind functions/metatables on the other end; this method will not work with closures, though.

What you described seems more like EC, a subset of ECS.

EC is Entity-Component, where entities have components, where components are both data and logic (see: Unity), whereas ECS is Entity-Component-System, where components are only data and Systems contain logic and act on components based on what components they have (see: Bevy)

1 Like