Howdy!
I’m trying to make a new class which is inherited from a base class, where the new class will be able to hold methods independent of the base class. However, whenever I try to call a method from the non-inherited class that isn’t from the inherited class, I get the error stated in the topic name.
This is not my code in the project, but it goes something like this
local ToBeInherited = {}
ToBeInherited.__index = ToBeInherited
function ToBeInherited.new()
local self = setmetatable({}, ToBeInherited)
return self
end
function ToBeInherited:DoAThing()
print("Doing A Thing")
end
-- ^ MODULESCRIPT A ^ --
----------------------------------------------------------------
-- V MODULESCRIPT B V --
local Class = setmetatable({}, ToBeInherited)
Class.__index = Class
function Class.new()
local Base = ToBeInherited.new()
local self = setmetatable(Base, Class)
return self
end
function Class:DoAnotherThing()
print("Doing Another Thing")
end
----------------------------------------------------------------
-- V INSTANTIATING THE CLASSES V --
local newClass = Class.new()
newClass:DoAThing()
newClass:DoAnotherThing()
newClass:DoAThing() will work as intended, but newClass:DoAnotherThing() will return an error, it’s like the methods in the non-inherited class are being ignored entirely. Is this a drawback to roblox oop? Is there a workaround or am i doing something wrong?
Thank you for your time ^.^