Question about OOP

Making this post in case the other one was hard to understand.

Let’s say I were to have a table in a module that contains in game bricks, let’s also say I wanted a brick to start rusting once it has been created. Let’s lastly say I also wanted a certain brick of my choosing to fully rustify when I input it as an argument when using a “PlayerRequestedRustify” function. How do I search for the brick I wanted to rustify in the module’s table?

Here’s what I got so far:

local Brick = {}
Brick.__index = Brick

TableofBricks = {} -- New bricks get inserted here

function Brick:new()
	local self = setmetatable({}, Brick)
	self.Color = "Red"
	self.Rust = 0
		while self.Rust < 100 do
			self.Rust += 1
	return self

function Brick.Create()
	table.insert(TableofBricks, Brick:new()) -- Not sure if this is right

function Brick.PlayerRequestedRustify(BrickToFind)
	if table.find(Brick.TableofBricks, BrickToFind) then -- Not sure if this is right either

function Brick:Rustify()
	self.Color = "Brownish Gold"
	print(self, "rusted!")
return Brick

For constructors, you should just define it as .new instead of :new since there’s no reason to take in the context of self for the constructor (because that’s what you’re trying to create). Otherwise, your creation code at Brick.Create is fine.

For the PlayerRequestedRustify function, table.find will work I guess, but feels a bit backwards. If you already have the BrickToFind, why not just call Rustify on it?

Lastly, it doesn’t seem like there’s any cleanup method. That’s fine if you want the instances of Brick to exist for ever. But if you want them cleaned up at any point, there should be a way to remove them from the TableofBricks table.

The reason why I wanted to have that extra function was simply to figure out if I could change an object’s info from the client at the same time of it being changed automatically by the server.

No need! This was only an example, but good catch!