# How do I configure a health potion

Get help using Construct 2

### » Mon Apr 28, 2014 1:35 am

OK, the situation is as follows:

1. There is a character with 2 stats, or in this case instance variables, pHP (player's health) and pMAXHP (player's maximum health), logically the player's health can not be larger than his maximum health at any given time.

2. There is also a health potion, which restores 20 health to the character, if his HP amount is less than MAXHP.

3. At some point the character's HP will be in a range of 81-100, leaving the question how to derive the needed number, for instance, the HP is 86, meaning that the potion sholud restore 14 HP. I was testing a few equasions, but none has seemed to work properly. So this is my way of saying 'yeah, I suck at math' and hoping that someone will end my misery.

Thanks in forward!
B
4
S
1
Posts: 16
Reputation: 432

### » Mon Apr 28, 2014 5:57 am

One of the easiest ways to do this is, have 2 separate sub events. The first triggers if the health value is below 81 and simply adds the potion and health values. The other triggers if the health value is above 80 and simply sets health to 100.

Another way to do it is, add the 2 values together as you are doing right now and, immediately after, have another event that checks if the health value is above 100. If it is, set it to 100.

finally, for a more compact, but less readable version, you could use the following:
min(<health> + <potionAmount>, 100)

Of course you need to replace the angle brackets items with the values you are using for the 2 items. This equation returns the lower of either the health plus the potionAmount or 100.

The real question for you is how many events you want to use and if you will be able to look at the event later down the road and remember what it is doing.

Hope one of these options works for you.
B
40
S
12
G
11
Posts: 331
Reputation: 7,752

### » Mon Apr 28, 2014 3:40 pm

I might have forgot to point out the somewhat obvious fact, which is that at some point in the game, the MAXHP value will be increased (otherwise I wouldn't even include the MAXHP value meaning the maximum would always be 100, I was just taking that value as an example).

So I guess the first option is out of the question. The second however is logical and works great for now.

I didn't really get the third one, I tried it, but it didn't work, it just went way over MAXHP...

Well as usual, it would be great if the number of events used is small enough to be effective. I'm grouping all these events separately so yeah, it should be pretty easy to spot it's position in the event sheet anytime Anyway, if you can figure something out, feel free to do that. As I said, the second option works for me and I might be sticking to it, just hope there will be no issues later on. Thank you for your help, it's very appreciated
B
4
S
1
Posts: 16
Reputation: 432

### » Mon Apr 28, 2014 4:04 pm

Just wanted to say, I only used the numbers above for readability. In all cases, you can replace 100 with pMaxHP, 20 with potionAmount and 80 with (pMaxHP - potionAmount). So, the first option could read:

...The first triggers if the health value is below or equal to (pMaxHP - potionAmount) and simply adds the potion and health values. The other triggers if the health value is above (pMaxHP - potionAmount) and simply sets health to pMaxHP.

As I mentioned in my first post, the last option is more compact but requires an understanding of the min function and for those who don't know how it works, it may make it more difficult to upkeep. However, for those users reading this post who would like to understand the third option min(<health> + <potionAmount>, 100), here is a breakdown of what is going on:

min() -> This is a function built into Construct that takes a list of numbers separated by a comma and returns the lowest lumber in the list. There is also a function called max() which takes a comma separated list as well but returns the highest number in the list.

Inside the parens, I have 3 values:
<health> -> the current player health value
<potionAmount> -> the value to be added to health when a player drinks a potion
100 (aka <pMaxHp>) -> This is the max health value the potion is allowed to raise the players health to.

The first 2 variables are added together in the function. The min then evaluates to see if <health> + <potionAmount> is lower than 100. If it is lower, the sum <health> + <potionAmount> is returned. If not, 100 is returned.
B
40
S
12
G
11
Posts: 331
Reputation: 7,752

### » Mon Apr 28, 2014 4:18 pm

If i accidentally encounter some inconsistencies, issues or bugs with the second option I'm using, I will definitely take a look at these and try to incorporate one of them. So thanks for clearing things up a bit
B
4
S
1
Posts: 16
Reputation: 432