How do I stop action from repeating on instance variable?

0 favourites
  • 6 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • 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?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Is it possible to give an eventsheet screenshot?

  • 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

  • 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.

  • 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!

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)