[solved]Health potion not working

I’m trying to make my player heal itself when it collides with a health potion
Currently when I pickup a health potion it replenishes the HP bar, however it doesn’t seem to heal my player, and when enemies shoot at it the player dies.

like for instance if my player has 3 health, enemy damages it for 2 hp, player picks up hp potion to heal him for 2hp which brings it back up to 3hp then enemies shoots it again but instead of bringing down its HP back to 1, it is immediately dead.

I’m guessing I should move the heal player action just below the delete power3?
But I dont know what would I do with the condition that I moved it from

You apply damage to variable and behavior

You change bar only to variable

You only heal variable

You should stick to one method or you will need to do the same for both behavior and variable
I would pick variable personally cause IN MOST GAMES ppl go with health extension just cause it is there
Where they do not need all the features it provides
And variable would be much more easy to control in my eyes
I mean like ask yourself
Do you really need armor? Damage reduction?
Cause looking at concept of AHP (Actual Hit Points) you would only subtract from variable different value from variable depending on SOMETHING and get pretty much same effect

BUT try both and find your own way

Ok so I’ve changed some stuff, so now the potion is working perfectly now and is healing the player as intended, however the HP bar still doesn’t track the current HP of the player, the bar can only decrease and not increase when HP is restored.

Reply to comment so person who you want to talk to actually get notification
I just found your reply by accident

On top you are using object variable same as in in expression for your hp bar
Yet on bottom you are adding to global variable

Nice, I’ve found it that I had to change the change the value of the hp bar and set it to player.health::health()

but now whenever I switch to a different level the health of the player resets to full, and I dont want that, I tried putting a lone condition of Health points of player = Player.Status.CurrentHealth but its not working.

Because behaviors do not hold value between scenes
You would need to set health behavior to global variable or stop using health behavior
And if you gonna set health of your player to global var you would need to do it in every scene
So i question is health behavior any good for you

No, I’m not using behaviors to store values, I’m using global variables
This right now is what I’m using, the hp still resets to full HP wen I switch scenes

What is this?

Looks like variable to me
Even worse two different variables

When this


For sure is behavior

I’ve already changed the two different variables into the correct one I want, goodness I didn’t even notice it, but it still doesn’t work.

Also I don’t understand what you’re trying to point out with the apply damage and heal player.

Your bar is changing based on behavior not variable
And behaviors do not hold their values per scene
So you need to either ditch using behavior
Or constantly set behavior value to variable value
Which makes it useless
OR at very least you need to set behavior to variable before you change scenes
And then at beginning of each scene have event to set behavior to variable value

For example you neeed to change player health behavior to global variable from which you subtract and to which you add values when player gets hit/healed

late reply but I had an idea to store values in global variables and I tried to base it off of my power ups for the guns

so basically I just move the apply damage action to the global variable currenthealth, but unfortunately when enemies hit the player after 2 shot it dies.

I still wonder why you use behavior if now you subtract from variable and use variable to change HP bar
Yet i wonder what is your current health cause if your player dies after 2 hits then it should be not bigger than 2

Then what exactly should i use to store HP values? I’m at my ends of what i know and this is all i know on how to do things?

1 Like

Look i gonna explain what you are doing yet i do not understand why

You have on your player health behavior
YET you are subtracting and adding from and to global variable when player gets hit
Also you are displaying that global variable by changing size of some bar to whatever that variable value is
So i wonder for what reason you even need that health behavior there?

Where on top of that behavior won’t work on between scene i mean it will but will not save its values
So you would need to pass value of whatever player health is atm BEFORE you change scene to global variable and then at beginning of new scene pass value of global variable back to health behavior

Imagine it as this if you go talk to me about this issue on discord right now
You NEED to writhe here BEFORE you leave “zero ok i go to discord and my nickname is LordRicardo on discord”
And now when you add me on discord you still need to go with “Hey zero its me ricardosalazar from gdevelop forum about health problem”

Where if you would just go with global variable it would be like you have same exact same nickname on discord as you have here
So there is nothing you need to tell me before leaving and after you contact me on discord

That is the difference between if you wanna use behavior+global var or only global var

Where using global var is as if
Imagine each time you say to me “it does not work” i have piece of paper and i write 1
Like literally each time i see you wrote this i write another 1 on that piece of paper
So i am manually adding 1 each time something did happen
Yet that info is stored on piece of paper i have
So if we would go to discord now and you write to me “it does not work” i still have all the info on how many times you did wrote that
Cause it is not held by something tied to one method of comunication
As if i would hit this heart icon

To increase its number each time you say “it does not work” which if we would move to discord would be lost cause it lives on here on this forum

Now you get the difference of handling it?

And now your next issue that your player dies after 2 hits
I would check condition which is required for player to die
What you check there?
Cause you should be checking if global variable is below 0
YET i would then use text object to print current health of my player which is your global variable Status.CurrentHealth
To see what kind of value it have and how it is decreasing when player get hit