Problems with OOP

Recently started to make a little project. I decided to use OOP since I haven’t used that in a while. I know this is how i used to do it, but now it doesnt seem to work.


This is the code. In the Grow function I print the plants time(which should be 10), but it prints nil.
Does anyone know why it doesn;t work?

By the way, the Parent parameter does nothing, so it shouldn’t be a problem.

That was a sneaky little mistake. Line 17: self:Grow(Parent), you want to call and pass the created object (not Plants:Grow(Parent)).

Edit.

When you call self:Grow() inside the .new() constructor, under the condition that the metatable is already linked to the class, it’s the same as calling Object:Grow() from whatever object .new() returns.

local PlantModule = require(...Plant)

local Plant = PlantModule.new() -- that self we return in the constructor

If we call :Grow(), the code will recognize the called function doesn’t exist in the returned object, so it will check in the Plants module.

1 Like

I forgot about that. Thanks for the explication!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.