I want to have an enemy class module (the ‘parent’ class) with smaller ‘child’ class objects as fields for handling health logic and status effects, for example.
Some of these child classes would need to access other child classes (let’s say I had a fire status effect for example, that needs to tick the health down every so often), and my method of achieving this works, but I want to hear what other people might do. Right now, I am storing the enemy parent class as a field in each child class so I can access the other components freely.
I’ve looked for other solutions on the Creator Hub but to no avail.
Sorry if the names ‘child’ and ‘parent’ classes are hard to understand, I was going to say components but I don’t think that fits with all the ECS stuff I’m seeing.
Storing the parent reference is fine, that’s what most people do.
You could also pass specific components when you need them. Like when you create the fire effect, give it a direct reference to the health component instead of the whole parent. Cleaner dependencies.
Or make the parent handle cross-component stuff. Fire effect just says “deal damage” and the parent routes it to health. Keeps components from knowing about each other.
Really depends on how complex it gets. For simple stuff like fire damaging health, just let them talk through the parent reference you already have.
I am not entirely sure what you mean so if I get it wrong sorry :d
Anyway if the “child” is an instance, let’s say for example a Character model. I’d say make a table using the character model as an index to the data/child of the object.
local PartToData = {}
function module.new(Character)
local newThing = {
Model = Character,
Health = 100,
Style = 100,
}
PartToData[Character] = newThing
return newThing
end)
So to access that model’s data we’d just need the model of the character
PartToData[Character] -- Will give you the table for the data of that Model or whateverrfdasdf