# How do I set max health to 100?

Get help using Construct 2

### » Sat Apr 16, 2016 6:23 pm

My player's health theoretically is 100. When my player picks up health, the health goes over 100. How do I stop this from happening?
B
11
S
3
G
2
Posts: 11
Reputation: 1,711

### » Sat Apr 16, 2016 6:57 pm

you can have an event that says

if health > 100 set health to 100
B
78
S
23
G
9
Posts: 579
Reputation: 14,365

### » Sat Apr 16, 2016 7:18 pm

System expressions wrote:clamp(x, lower, upper)
Return lower if x is less than lower, upper if x is greater than upper, else return x.

Player(varHealth=92) on collision with Bonus(+25) ..set varHealth to.. clamp(varHealth+25, 0, 100)

varHealth100.capx
B
67
S
24
G
7
Posts: 1,519
Reputation: 11,104

### » Sat Apr 16, 2016 7:43 pm

I've always used two variable current hp and max hp being that at the time max hp can be used to be changed if let say an upgrade call for extended life such as 50 more to max hp to total 150 and had it done by if current hp is greater then max hp then set value of current hp to max hp.

This way you can modify the max hp if you are doing a level up or building better ship etc.

You can always used the current hp as a hp display alone but the max hp would be the barrier from going over.
B
52
S
24
G
6
Posts: 391
Reputation: 7,855

### » Wed Apr 20, 2016 3:47 am

Thanks guys! Problem solved
B
11
S
3
G
2
Posts: 11
Reputation: 1,711