#How you implement 'Component's logic to your classes?

1 messages · Page 1 of 1 (latest)

muted pawn
#

Let's say you have an entity class with these properties:

local Entity = {
Model = instance,
Physics = PhysicsClass, -- exposes methods for moving the entity + applying impulse
Movement = MovementClass, -- controls movement logic lol
Combat = CombatClass -- combat and special abilities
}

Seems simple, but once components start depending on eachother, it becomes so overwhelming. Like, if movement depends on physics in a certain method, but physics haven't loaded yet, it will just throw an error.
I know what's ECS, with components being just data, systems controlling logic and they're like loops in a stepped connection. But I don't think switching to a loop-based approach fits well for my project

true granite
#

i just congregate dependencies into one or two functions so its easier to manage

#

I think it would also be a good idea to merge physics and movement class in yours since they both only do movement logic

night stratusBOT
#

studio** You are now Level 5! **studio

soft marlin
muted pawn
#

It was supposed to be intuitive but feels so awkward to implement

#

Its not first time doing stuff like this, I used similar approaches in my last project but didnt turn out as I expected

muted pawn
soft marlin
#

no problem with that i dont think

muted pawn
# soft marlin by the time scripts require a module, all modules are already loaded

Ahh quite difficult to explain myself without texting too much, 'll tryna elaborate my situation:

I have a Player class, and those properties I mentioned earlier aren’t modules — they’re instances of classes. I have a more clear issue in this same class with a “replication component.”

This replication component pulls data from the player instance and its components to keep the client updated with things like skill cooldowns and similar states. The problem is that this component obviously has to be initialized last. And I could just treat it as an exception and explicitly do something like:

self.Replication = ReplicationComponent.new(self)

at the end of PlayerClass.new(). But this is one of those cases where structuring things as components starts to break down.

I’m trying to use components more as a way to organize the project overall, not just for a specific isolated system. It feels intuitive at first, but in practice I keep running into edge cases like this and having to add special handling for them.

So I’m wondering — do you (or anyone) structure components inside classes like this? And do you think situations like this are normal or am I just missing something?

soft marlin
#

can I see an example of it from a game file

#

i might understand your problem better that way

#

have you heard of the singleton pattern for objects?

muted pawn
#

Sure, here ya go. But it’s not really necessary to go too in depth — I already have workarounds for these situations. The issue is that they come up very often when I try to use components as a way to organize per-entity logic. I’m actually a bit traumatized from my last project, where I pushed this component approach too far and it ended up becoming a complete mess. Now that I’m starting a new one, I’m trying to be more careful, but I’m still not getting good results

muted pawn
#

I really just want to find a way to split my player logic (and other entity types) into clean, organized parts. So I could do simple things from external systems like:

Player.Character.Animations:Play("Dash")
Player.Combat:Stun(2) -- seconds

without having to worry that much about initialization order