How to substract the damage from two variables?

In the Take Damage function, first set a local variable DamageLeft to the inputted damage value.
Then where you subtract from shield, also subtract the shield from DamageLeft.

Then AFTER THAT, subtract DamageLeft (clamped so it doesnt go negative) from Energy. If the shield absorbed all the damage there wont be any DamageLeft (it will be zero) when you get to that part and it will subtract zero Energy.

But ff there is any damageLeft it will subtract whatever is left from energy

I have something like “ENERGY” and “SHIELD”, both are types of health.
Let’s say that both, ENERGY and SHIELD have a value of 100.
If someone deals me 150 damage, it will be first subtracted from SHIELD and the leftovers will get subtracted from ENERGY.
So the result should be ENERGY = 50, SHIELD = 0.

The clamp there makes it bit hard to know how much “value” is left to subtract from the ENERGY. Without the clamp the SHIELD goes into negative so i could handle it with a branch and subtract the SHIELD (if negative) from the ENERGY. But that clamp is needed so it won’t regenerate above the SHIELD_MAX.
I could remove the clamp and set the SHIELD to SHIELD_MAX value if SHIELD value is above the SHIELD_MAX. But not sure how to do it, because i can’t connect two float values to one SET node.

Here is how i handle the damage, pretty simple.

Here is the regeneration logic.

I like that version even more.

Could you post this as a answer to my question and not as a comment? I mean, i don’t think that this can be made better than you did and it’s rly easy to understand lol.

or if you want to be a little less proper read on. you can let the numbers for the shield go negative if you wanted to then just leverage that as shown in the picture below. the idea here is you subtract the damage from the shield then check if the result is negative and if it is then you add that number to the energy. this in essence subtracts from the energy. then the last step is to clamp and set the variables. i gave it a quick test and it seems to work without issue.

edit: converted to a answer on request of asker. was formerly a comment on mightyenigmas answer