I use Gdevelop for a year now, but I want to add health, and I followed the lesson again because I haven’t use Health bar for a LONG TIME! so, I followed exactly what the lesson wants me to do but it did not work…
I did not get it why it did not work, I added everything. I added the extension, I added behavior, I added, “Interface” and I even added a code…
But here we care only for width so 200 is only value that matters here
Now since i use health extension (same as you do) i simply use formula
200/Player.Health::MaxHealth()*Player.Health::Health()
To change width of my health bar object
If i would use variables i would need 2 of them on my Player HPMax and HP
And now formula would look like
200/Player.Variable(HPMax)*Player.Variable(HP)
I put this action in event WITHOUT any condition so it is updated each frame
And now bar will shrink if you made event to subtract health from player via health extension action or if you would subtract form Player.Variable(HP) if you would go with variables instead
Avoid using fixed numbers in the formulae; if you change the size of the image, then you’ll be stuck finding and replacing all events that refer to the old size. Use the object properties and functions instead (Width() in this case).
However, in order to resize it you’ll need to store the original bar width in a variable. Otherwise, the resize will be based on the health bar’s current width. So, at the start of the scene set: