Life bar issue...

Get help using Construct 2

Post » Tue May 28, 2013 10:52 am

Greetings everyone. I set up a life bar for my main hero awhile ago, and it has been draining fine until I decided that I wanted it to regenerate 1 health per a certain amount of points earned. My event looks like this:

Event condition(<system> <compare variable> "score" greater than or equal to 25)
Action(<Hero> <add to> instance variable "Life" +1)

My hero has a max life of 5 chunks in the bar that he starts out with, but when he hits 25+ score and the above event activates the health line inside the health bar frame grows and shoots across the entire top of my screen! I can then get hit as many times as I want because of the ever growing health bar... Am I doing something wrong? I have my health bar set up just like Kiyoshi's guide showed in the tutorials section of scirra.com with my own graphics of course. Link: Kiyoshi's Life bar guide. Can anyone explain why something like that would happen just to add a single chunk back onto my health? Thanks in advance!
B
8
S
1
Posts: 42
Reputation: 1,159

Post » Tue May 28, 2013 11:01 am

It's because the condition is always true, the score is over 25 once it hits 25, and it's adding to the health constantly, I think you need a trigger once condition, at least...Pixel perfick2013-05-28 11:02:51
As long as I can move left, right and fire, I'm Happy...
B
42
S
15
G
11
Posts: 655
Reputation: 12,260

Post » Tue May 28, 2013 11:16 am

looking at this again you will need to rethink your events...

you need to give your healthbar a variable, or a global variable if you prefer, lets call it regen, then when regeneration is possible trigger:...

set "regen" to score

>score => regen + 25...        add 1 to health
Trigger once                  set "regen" to score

So every time your score is 25 over the last health top up it will add another and re start the "regen" counter...Pixel perfick2013-05-28 11:32:15
As long as I can move left, right and fire, I'm Happy...
B
42
S
15
G
11
Posts: 655
Reputation: 12,260

Post » Wed May 29, 2013 5:08 am

Hey Pixel perfick, thanks for the response! I'm using triggers now and it only goes up 1 health chunk at a time yay. But now if my health is full and I have not taken any hits by the time I hit the set score the health bar with grow 1 piece more than my max health each time conditions are met. Is there a quick event or something I could add that would not let it grow beyond 5? Thanks much for any feedback!
B
8
S
1
Posts: 42
Reputation: 1,159

Post » Wed May 29, 2013 5:44 am

Nevermind I got it. Thanks for all the help!
B
8
S
1
Posts: 42
Reputation: 1,159

Post » Wed May 29, 2013 4:43 pm

Sorry for delayed response, glad you got it figured...
As long as I can move left, right and fire, I'm Happy...
B
42
S
15
G
11
Posts: 655
Reputation: 12,260


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 6 guests