I aim to inherit the functions from my Hostile class and use them with my Boss class.
Here is a simplified version of my code:
Boss module:
local Boss = {}
Boss.__index = Boss
function Boss.new(class, datatable)
local newhostile = Hostile.new()
setmetatable(newhostile, Boss)
return newhostile
end
function Boss:ManualOverride()
self.Conditions.HostileDies.Met = function()
print"BOSS DIED! WIN!"
end
end
return Boss
Hostile class module:
local Hostile = {}
Hostile.__index = Hostile
function Hostile.new()
local hostile = {}
setmetatable(hostile, Hostile)
hostile.States = {}
hostile.Conditions = {}
return hostile
end
function Hostile:Spawn(spawnpart)
print"spawned"
end
Core script calling my boss module:
local boss = BossModule.new(bosstype, BossData.Data[bosstype])
boss:Spawn(spawnpart) -- errors, spawn not recognized and is nil
boss:ManualOverride()
Doing this does not allow me to inherit the Spawn function from the Hostile class. This means I can’t call Spawn from my boss object. Can someone explain why? Am I overriding the old metadata? How do people usually go about extending classes correctly?
.