{Solved} How to increase the maximum value of Health

Helo guys, I have such a problem.

The player has 200/200 Health at the start of the scene. So the maximum is 200. He will take some damage during the game, but if he drinks a health potion, he will reach the maximum health value of 200. So far everything is working.
In the later stage of the game, there will be a situation where the maximum health value will expand from 200 to 230. Every time the player picks up the Heart object, the maximum health value will increase by 30. But somehow it doesn’t work. When I pick up the heart, the maximum health value does not increase to 230 and the hero gets minus 30 to the current health. Thanks for any advice. :-).

1st of all don’t invert variable conditions

Condition is checking if variable is heath is higher than max helth
If you invert it then it is checking if its lower

So you could just not invert it and check if its less than

2nd of all consider do you want to use object variables instead of global variables
IF you delete your player like he dies and he have many lives
You will lose all variables value

Not to mention global vars work between scenes

Next
1 - you did understand you should just add value to variable
2 - so you should follow same logic here where you simply add 30 to max health instead of adding max health to max health + 30

Lastly why not go with variable names
HP and HPMax
Look how long your var names are already
You will need to save it later
And it will become way too long since you will save structures

Anyway my only suspect here is that you set max health to max health + 30
But that should work
If not then i have no idea

Ok,I made a few changes but the result is the same. :(.

I did read OP 5 times just to be sure i get you right
Cause i have strong doubts on what is causing it

I want you to test few things
Cause all you have in events is perfectly fine in my eyes

DO NOT CHECK these things at a same time
One thing at a time

Here at beginning of scene

Set hp max to exactly 240

And now check if when you pick up heart you still get -30 or will it be 10

Next here

1st thing to check
Add 50 and check does it will end up with - 30 or -50

2nd under change hp max add 30 but above delete health so between them
Add change HP add same value as you add to HP max

Tell me what did you get

I set Max HP to 240 and plus 50 if I drink a health potion.
When I grab the Heart it still gives me minus 30.

I think i dont understand this:
but above delete health so between them
Add change HP add same value as you add to HP max

This is most important part the 1st part you just wrote
Look you had before HP MAX at 200
You add 30 to your HP MAX when you get health potion
And you get -30 HP or HP MAX whatever

What is important here
You changed HP MAX from 200 to 240
And instead of adding 30 you are adding 50

So now it should give you either -50 or -10 but not again -30
Which means what you just changed have ABSOLUTELLY NO effect for what is causing it
I would suspect you have somewhere event that is setting HP to -30
Cause there is no other way to explain it

Because there is NO WAY for it to still be -30 AFTER you changed max hp value and for how much max hp you get after you pick up health item

About what you don’t understand
This is less important but it can actually fix stuff
Or more like let you bypass your bug while not fixing it

You have action here
image

Change variable HP MAX add 30
Delete Health

I ask you to add there one more variable change but for HP var

Change variable HP MAX add 30
Change variable HP add 30
Delete Health

Ok problem solved :D.

I just changed the width of Health_current from 200/HP_Max*HP to HP
And I added the width of the bar

It works.

Thank you ZeroX4 for your time. I really appreciate it.
:slight_smile:

1 Like

Random thing, but you shouldn’t have Trigger once in these events. You are already making sure the condition will not be true again by deleting the object or changing the variable.

Also, this will not work properly if you collide with more than one potion or health upgrade at the same time. In order to take into account all colliding objects you would need a “repeat for each” sub event.