I have a stat sheet interface in my game that I want to update every time I equip an item. When I equip a helmet the output does show that the stat is increased but it is not shown on the interface.
For example:
defense.text = str(playerstats[“Current_Defense”]) shows a defense of 17 when loading the game but doesn’t change after equipping a piece of armor that adds 4 defense.
I attempted to duplicate the player stat resource but that didn’t work. Any help would be appreciated. Thanks!
You are assigning text to your labels in the _ready() function.
The _ready() function runs once when the scene is added to the tree.
So when you add the item to the players inventory the function has already run.
When a players stats have changed you have to update the text of the label.
Right this code will only update the display on _ready() when the game starts. Each stat is being converted into a string and copied into the label’s text once and only at the start of the game. Let’s move it to a update_display function then call that when we update the playerstats, maybe using the changed signal resources have?
It’s still not working. Perhaps i’m calling the function incorrectly. Should I instantiate it? I used var CharacterStatsheet = load(“res://Equipment/character_statsheet.gd”) for the variable followed by CharacterStatsheet.update_display(). When I tried instantiating it before it returned all the values of the resources to null.
Could you post how you are updating the stats when equipping new items? Seems like you are loading the script and need to create a reasource or load a resource directly.
```
paste code with code formatting too please
```
on code formatting, close the </> button in the editor will make a block for you to paste code in it will look like this when you click the button on a new line
Thanks for your help. I ended up getting rid of the resources for my stats and used variables for my stats on my character script and used signals to update the label.