I new to lua OOP and wanted to ask is there a way to override a parents function but still be able to call it
Example:
local ParentObject = {}
ParentObject.__Index = ParentObject
function ParentObject.Print()
print("this is the parent")
end
local ChildObject = {}
ChildObject.__Index = ChildObject
setmetatable(ChildObject, ParentObject)
function ChildObject.Print()
self.ParentObjectPrint() -- Don't know how to do this
print("this is the child")
end
so calling the functions will look like:
ParentObject.Print()
-- Prints 'this is the parent'
ChildObject.Print()
--Prints 'this is the parent' then prints 'this is the child' directly after
local child = ChildObject.new() --just image I have a .new() function
child.Print() -- I would still want to print the parent function BUT
-- the parent function self will now = to the child
Can you come up with a fully working example except for that one line, just so we have common thing to look at? There are a lot of ways to do inheritance in lua so it would be helpful to know exactly how you’re doing it.
Basically I have and update function in the Parent object that updates all the back end stuff like healthGui, ammoGui, etc. I also want this to update for the child but I want the child to update the back end stuff. I am currently getting around this but creating a serperate function called base_update that the child will never overried and just call base_update from child update