#Better access to components
1 messages · Page 1 of 1 (latest)
The stat resource itself is dropped on the unit node and then handed to the component by the script
I think the current setup you describe is fine. You could maybe shortcut some of it by including a function on the unit class, like "increase_stat(STAT, amount)" that will check if that unit has:
- A stat component
- The specified stat
- If so, increase that stat by amount.
Then your code would look more like "unit.increase_stat(STAT.DEFENSE, 3)" or something, but it is still readable, and management of stat changes can be delegated to functions that can be called instead of updating stats directly.
It is also a good idea because each node may use the component differently.
Leaving the implementation to its owner means that it can be more easily re-used somewhere else. And that other nodes don't have to worry about the owner AND the component.
Careful with this. If the stats are indeed coming from a resource, each unit using the same resource would get a stat increase when increase_stat is called
That is what local_to_scene is for. But ye.
When every resource is local to scene, why use a resource? 🤔
IMHO, resources should be shared static(ish) data. Nodes should reference them, and then keep track of any dynamic state themselves.
Not yucking anyone's yum. There are a million ways to do anything in game dev
I overlooked the fact that they were applying the change directly to the stat resource...
@merry otter personally I feel better practice would be to assign stats to the units directly. The stats resource informs the Unit what its base stats should be, but then you can modify the Unit stats directly without fussing with the Stat resource itself (which , as Mysersguy suggests, could cause issues, i.e. accidentally updating ALL unit stats).
They aren't showing any actual modification, only accessing
The resource set function has been modified in order to save and move value.duplicate() instead of the actual resource
As a data structure mostly.