I’m rewriting my entity system once again with Composition and OOP Classes in mind. The issue is that I don’t know what I’m doing. There are two module scripts named EntityClass (Which, from my knowledge, is the superclass) and SubclassEntity. What I’m trying to do is that I want EntityClass to be the base of the subclass module, containing things such as the spawn and despawning of entities alongside basic movement stuff like pathfinding.
On the other hand, I’d also want SubclassEntity to house specific functions exclusive to that module such as attacking alongside using the functions from EntityClass.
EntityClass
--[[MODULE]]--
local EntityMoodule = {}
EntityMoodule.__index = EntityMoodule
function EntityMoodule:CreateEntity()
local self = {}
--//TBA
return setmetatable({}, EntityMoodule)
end
return EntityMoodule
SubclassEntity
--[[BASE CLASS/SUPERCLASS]]--
local EntityClass = require(script.Parent)
--[[MODULE]]--
local SubclassEntityModule = {}
SubclassEntityModule.__index = SubclassEntityModule
setmetatable(EntityClass,SubclassEntityModule)
function SubclassEntityModule:NewEntity()
--//TBA
end
return SubclassEntityModule
If you are doing EntityClass as the superClass, you would set EntityClass as the metatable for Subclass, right? So when Subclass doesn’t find a function inside of itself, it will try search inside Entityclass, but I don’t think that’s what you want to do.
The reason why I’m using a class-based system instead of putting them all together is that I’m planning on making two subclasses, those being a Melee and Ranged class. Of course, you already know what those classes might be about.
Do you mean like inheriting from EntityClass?
If so then
local EntityClass = require(script.Parent)
local SubclassEntityModule = setmetatable({}, EntityClass)
SubclassEntityModule.__index = SubclassEntityModule
function SubclassEntityModule:NewEntity()
local self = setmetatable(EntityClass:CreateEntity(), SubclassEntityModule)
return self
end
return SubclassEntityModule
(I’m stupid and don’t understand your question so this might be 100% off topic sorry)