Health Bar trouble

Hey guys, so here’s what’s up.

I have two bars; an HP bar for health and an MP bar for magic. Naturally of course.

And i have a frame surrounding each bar.

So when the Player casts a spell, the MP bar goes down. However, when Player comes into contact with Item, the MP bar gets refilled. But when i collect more Item than i need, the MP bar just continues to grow outside of the frame.

What i need is to somehow set a max level that the bars can’t exceed. Or maybe if the mana bar is full then Item cant be collected.

i’m sure if i just mess around with variables i can find a way, but im still having trouble with the nature of variables in the first place

Try something like:

If player is in collision with MPItem and Variable(MP) < 100 then Do + X to Variable(MP)
If Variable(MP) > 100 then Do = 100 to Variable(MP)
Do = Variable(MP) / 100 to scale of MPBar

1 Like

You can do either of these, yes :wink:
We can’t help you without knowing how you handle your bars.
There are examples out there so you can see how things work. This one from @Silver-Streak has bars, for instance: Not-A-Vania by Silver-Streak
You can download the whole project and see for yourself.

Kudos for Gruk for the shoutout. ddabrahim’s suggestion is close to how I did it. For what you’re wanting to do (MP), make sure your “refills MP” condition to has “MP variable <100” in it, too.

Edit: Just realized what I mentioned above is pretty much exactly what ddabrahim suggested.

I also recommend checking out the health bar examples on the main site: https://gdevelop-app.com/game-examples-starters/

The same concept can be done for MP.