#General question about saving stats

9 messages · Page 1 of 1 (latest)

spring oracle
#

Yeah resources are great for things like this. Fron what im seeing, you already have a great structure to make resources already. I can give you some advice /steps on how i did things on my rpg which also handles entities with many stats.

  1. That script you use for all champions extend from Resource rather than Node this allows you to create new resources as .tres files and store them to easily manage and add more, you could also name the class like champion_basestats or similar, you can make a champions folder or something and add them, (right click add new resource, then resource from champions_basestats class) this will make a file that you can modify its export stats on the editor to quickly add more.
  2. On your actual champion scene, you can add a var which holds the data like @export var base_stats : champion_basestats this allows you to drag and drop the resource of the corresponding unit onto it so you can access it anywhere from that entity like print(base_stats.base_armor) etc.
  3. You can add all the functionality that modifies those stats inside the class so you can do whatever you need from there like so base_stats.heal(amount) etc.
  4. Just keep in mind that if multiple entities point to the same resource for example if a minion has a minion.tres resource, all instances of that entity will share the same resource, to avoid this you can duplicate the resource in case multiple scenes use it. base_stats = base_stats.duplicate().
    If this way of doing it is not what you loikin for im sure there are other ways using resources as well to do this. Depends on your needs for the future!
sage oak
warped ruin
#

@sage oak thanks for the link, looks very handy, it is for Godot 3 and Im using Godot 4 so I will look for a newer version, but thanks for the tip

#

@spring oracle thanks for the info, this is what I was looking for, I made a Resource script for my champion stats(champion_stats.gd), and one for my enemy stats(base_enemy_stats), also made a few resources for both champions and enemys and changed from using the BaseStatComponent to the actual resources.
Now it should be working fine, but I still have a question. In my BaseStatComponent.gd script I had a few functions, and also a _ready and a signal, but this code is not used because when I extend from Resource it doesnt run callbacks.
Now my question is what would be the best way to fix this?
I added a screen of my champion_stats.gd, the code you see stands under all the export var stats(health, attack damage, etc)
But already thanks for the help.

spring oracle
#

You could put your previous things inside the _init() function of the class, alternatively you can run a custom initializer function on your character's ready function base_stats.initialize() or something.

warped ruin
warped ruin