I have a parent class, Question, that has a method Init(). This method calls Load(), which is defined in its subclasses. My Goal is to call Init() in subclasses, so it runs the Parent Class Init(), which then calls the Load() in the subclasses.
My problem is, that although the subclasses run Init() with the data of the subclass, it tries to call Load() in the parent class.
function QuestionClass:new(Folder:Folder,Answer:string)
return setmetatable({Level = Folder.Parent.Name,Difficulty = Folder.Name,Answer =Answer,Debounce = DebounceModule.new(3),Folder = Folder},QuestionClass)
end
function QuestionClass:Init()
for _,v in pairs(self.Folder:GetChildren()) do
if not v.Value.Value then
self.Model = v
print(getmetatable(self))
self:Load(v)
v.Value.Value = true
break
end
end
table.insert(QuestionClass.Questions,self)
end
The MetaTable shoes that there is a Load() method,
["Load"] = "function",
["__index"] = ▶ {...},
["new"] = "function"
}
but it errors, saying it cannot find it.
ServerStorage.MainModule:44: attempt to call missing method 'Load' of table
Here is the subclass:
function ImageQuestion.new(Folder:Folder,DecalId:string,Answer:string)
local self = setmetatable(QuestionClass:new(Folder,Answer),ImageQuestion)
self.DecalId =DecalId
self:Init()
return self
end
function ImageQuestion:Load(Part:Part)
local Decal = Instance.new("Decal",Part)
Decal.Texture = self.DecalId
end
I have tried putting a test class Load() of the parent class, and it runs instead of the subclasses.
This doesn’t make sense to me, as the metastable clearly shows it has a Load() method. Any help would be appreciated.