Health Bar Limit

Get help using Construct 2

Post » Sun Apr 20, 2014 12:26 pm

Hi,

I attended a game jam in Luton last week organised by Train2Game & used Construct 2 (Free Version) to develop a prototype platform game. Haven't used construct 2 for quite a while & am at more or less beginner level with using it. However i managed to get the game working with most of the basic features, moving, interacting with objects, environments, enemies, reaching the end point of the level etc , but have spent the last few days since the game jam practicing, adding some of the items & features that i didn't get time to add due to time constraints with it being a 48 hour event...

Most of the game is now working relatively good (I hope so) & am able to understand how to fix some niggley problems that occur but i have just 1 minor problem that i can't figure out how to solve & that's with the players health bar. It works fine as it should, have the health set at 100 & each hit reduces the bar by 25%, have also added health items that increase the bar by 25% which works fine, the only exception is when the health bar is already at 100% & a health item is picked up the bar keeps increasing,

I'm sure that its probably a simple fix but i can't figure it out at the moment. Is there a way to stop the bar from increasing once it is at 100%?

Again i'm just getting back into using the program, haven't used it in months so trying to understand the features etc,
Any help would be greatly appreciated,

Thanks :D
B
8
S
1
Posts: 4
Reputation: 1,156

Post » Sun Apr 20, 2014 12:42 pm

You just need to add condition that will either limit or reset the bar, or both.
To limit it would go like this: If bar health < 100%, then add life
to reset the bar, Make MaxHealth and Health instance variables and in event you would do something like this: if health > then varMaxHealth, set bar 100%, set varHealth to varMaxHealth
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
86
S
27
G
21
Posts: 1,973
Reputation: 19,200

Post » Sun Apr 20, 2014 1:11 pm

AFKATM so I have to be quick - this sounds like a job for the clamp expression!

i.e
clamp(playerHealth, 0, 100)

https://www.scirra.com/manual/126/system-expressions
B
57
S
19
G
9
Posts: 639
Reputation: 9,533

Post » Sun Apr 20, 2014 9:33 pm

Thanks guys will check that out,

Cheers for the info...:)
B
8
S
1
Posts: 4
Reputation: 1,156


Return to How do I....?

Who is online

Users browsing this forum: alextro, ivanski1983 and 11 guests