How do I stop action from repeating on instance variable?

Get help using Construct 2

Post » Fri Apr 18, 2014 5:57 am

I have player with an instance variable "health" set to 1 on start, then I have an instance variable "hearts", which refers to the heart object you can pick up. I have it setup as Event>player>hearts=5>player set health to 2. So I pick up 5 hearts then the health changes to 2, that's where the problem is, the player can not take damage when the hearts count is still set to 5. The action is just keeps on repeating and keeping the health at 2 while the hearts instance variable is on 5. If i pick up one more heart making the variable count 6 then the damage to the player works as normal. How do I fix this?
B
50
S
17
G
2
Posts: 110
Reputation: 4,484

Post » Fri Apr 18, 2014 5:59 am

Is it possible to give an eventsheet screenshot?
B
23
S
4
G
2
Posts: 364
Reputation: 2,392

Post » Fri Apr 18, 2014 8:12 am

If I understand correctly, every time the player gathers 5 hearts you want to add 1 value of health to the total amount of health...(?)

The problem is that once you've gathered the 5th heart the =5 stays true for every tick, thus adding health continuously. That's why when you gather the 6th heart the problem goes away.

You need to reset the heart count after you add the +1 to the total health, so that the =5 condition doesn't hold true.

See this example capx -> http://www.eli0s.com/Tests/HeartCount.capx
composer - multimedia artist
www.eli0s.com/en/
B
69
S
27
G
6
Posts: 1,146
Reputation: 10,379

Post » Fri Apr 18, 2014 9:25 am

@eli0s thanks a lot that fixed it. I don't know if you can answer this but is there a way to check if the picking up 5 hearts event has already run once, so on the next 5 hearts that get picked up I can add 1 more to the health and set a new animation? At first I had it set up to hearts = 5 then +1 health and set frame animation, then hearts = 10 then +1 health and set frame animation, but since I am now resetting the hearts variable after 5 are picked up I don't know how to check if the event has already happened so the next time I pick up 5 hearts I can add health and change animation frame.
B
50
S
17
G
2
Posts: 110
Reputation: 4,484

Post » Fri Apr 18, 2014 10:33 am

To check you can create another variable say Heart collection check

So on first 5 collection set check=1

if check = 0 and heart =5 then health +1 and +1 to check
if check = 1 and heart = 10 then health +1 and +1 to check
if check =2 and heart = 15 then health +1 and + to check

I hope this is what you are looking for!
Every Game is a Good Game it's just few people like and few does not! Keep coding people some day you will be a "NOTCH".
B
21
S
6
G
3
Posts: 85
Reputation: 4,607

Post » Fri Apr 18, 2014 12:51 pm

twg wrote:@eli0s thanks a lot that fixed it. I don't know if you can answer this but is there a way to check if the picking up 5 hearts event has already run once, so on the next 5 hearts that get picked up I can add 1 more to the health and set a new animation? At first I had it set up to hearts = 5 then +1 health and set frame animation, then hearts = 10 then +1 health and set frame animation, but since I am now resetting the hearts variable after 5 are picked up I don't know how to check if the event has already happened so the next time I pick up 5 hearts I can add health and change animation frame.


You only have to link the Health variable to the animation frame. Whenever the value goes up, the frame number will correspond also.

Re-download the example capx, I have updated it to reflect the linked frames.
composer - multimedia artist
www.eli0s.com/en/
B
69
S
27
G
6
Posts: 1,146
Reputation: 10,379


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 4 guests