How do I make a class that inherits from multiple classes?
Making a class inherit from a single classs is easy, (just extend the table) but how do I make it inherit from multiple classes?
This is the currernt setup I have.
The NPC class I have currently uses the FSM ( finite state machine ) and State ( which is wirtten in the same module as the fsm class but independent from the fsm ) class.
The current setup I have simply stores the fsm instance as a variable in the npc class
The problem I have is that the fsm instance doesnt have a direct access to the variables of the npc class. ( the comments are the examples )
The only way I could think of is passing the npc object as a aruguemt the same way “self” works. Im not sure if this is the right way, it feels messy and prone to bugs…
How do I use multiple classes in a class?
Thanks for taking your time
Edit:
The example only inherits from one class currently, however I will be adding more classes to it.
This might be a bad example but I need help coming up with the basic strucure that allows multiple classs inheritance. thanks again
local MyClass = game:GetService("ServerScriptService").MyClass
local FSM = require(MyClass.FSM)
local State = FSM.State
local NPC = {}
NPC.__index = NPC
NPC.fsm = nil
NPC.pursuitTarget = nil
function NPC.new()
local new = {}
setmetatable(new, NPC)
new.fsm = FSM.new({
pursuit = State.new({
enter = function()
--I want to check if NPC.pursuitTarget is not nil here
print("Enterd pusuit state")
end,
update = function()
--walk to target
end,
})
})
return new
end
return NPC