How do I set max health to 100?

Get help using Construct 2

Post » 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

Post » Sat Apr 16, 2016 6:57 pm

you can have an event that says

if health > 100 set health to 100
Image
B
71
S
20
G
9
Posts: 553
Reputation: 13,835

Post » 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
Image
B
65
S
23
G
7
Posts: 1,501
Reputation: 10,888

Post » 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,845

Post » Wed Apr 20, 2016 3:47 am

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


Return to How do I....?

Who is online

Users browsing this forum: Anonnymitet, DeXVinogradov, leena222, tatogame and 17 guests