Healthbar not working on click

Hello community,

I’m a noob - so apologies!

  • I’m trying to make a desktop game. 3 squares and beneath one of them is an object… find the object behind the square - basically.
  • My game has a sprite called healthbar.
  • every time player clicks on a square (block), it deletes and a percentage of health is reduced.

BUT: what isn’t happening is… the reduction of health when clicking the square (block).

I’ve been following this tut: How to Add Health Bars to Your Games in GDevelop - YouTube – How to Add Health Bars to Your Games in GDevelop

if i move the lines to The cursor/touch is on []Block, then it does move.

Any ideas please?

Is the health bar not going down at all, or does it do down just once on the first block clicked and then it stays there?

In your last action you are deleting block object which have HP variable
So after you deleted it there is no HP to read from

Hi MrMen,

It’s not going down at all :frowning: from the click event. If I move the two ‘Change width…’ up one level … The cursor/touch is on BLOCK… then it does work but not as expected.

Hi ZeroX4,

That had occurred to me, so I moved DELETE order to the bottom.
I also removed DELETE and still the healthbar doesn’t behave as expected.

Is 311 horizontal size of blue object which is your health bar?

Can’t tint them correctly so use your imagination
On the left that broken bricks object is your yellow block
Above player broken bricks object is your blue block (healthbar)

Now this YellowBlock.Variable(Health)/100*120
YellowBlock.Variable(Health) variable which i set on yellow block to 100 called Health
/100 that 100 Health which is max Health
Since Health variable will change (decrease) i just put there number as indication what is the max Health
*120 is vertical size in pixels of that object so engine knows what is 100% of vertical size and can change it size proportionally to how i decrease HP
Now you just click on the block on the left which is your Yellow block and the block above player which is Blue block (healthbar) will shrink
When it reaches 0 Health it will be deleted

Are there any other events that update or modify healthBar width?

Sorry @MrMen,

it does go down once, then stops - just check it again.

So, I’ve setup a new scene - as test.
imported Block as global sprite but created a fresh sprite for healthbar.

  • I removed Delete.block
  • cloned Block, so I have at least two blocks (squares) on the screen now.
  • i click first block (repeatedly - it works fine - healthbar is going down).
  • when i click second block… it kinda works… the healthbar is jumping to maxHealth and then reducing some.

If the Delete.block is in there - it just doesn’t work :frowning:

So what I did was …
Create a separate sprite and setup same variables. then …
Everytime I click on Block, just subtract from the NewBlock.

Thanks Guys for your help.

I’m not sure why you’re using an object variable. You could use scene variables named health and maxHealth. Also, Gdevelop now includes resource bars that accept a value.