How do I Make it so an action is only done once even if it's called twice? (SOLVED)

0 favourites
  • 5 posts
From the Asset Store
Change the size and position of everything without calculating anything!
  • So, I'm making a game which is a platformer and there are spikes the player takes damage for falling on, but in some places there are big rows of the spike sprite, and if the player falls touching two at a time, then they take 2x damage because the action is executed twice at the exact same time. I have a system where when the player gets damaged, they have invincibility frames, but this still happens because both spikes are hit precisely simultaneously. How should I go about solving this?

    Edit: I was being dumb and had a wait action before setting the timer for invincibility because reasons.

  • You can set a Timer when the character collides with a spike. Only reduce its health if the "invincibility" timer is not running. Or you can use a variable for the same purpose.

    Player On Collision with Spike
    compare variable InvincibleTime<time
    ... Player Subtract damage from health
    ... Set variable InvincibleTime to (time+2)
    
  • Yes, that is exactly what I did, as I said, the problem is two spikes collide with the player at the exact same time, so it triggers twice nonetheless

  • That should not happen with my code.

    If it still doesn't work correctly, please post a screenshot of your events.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • That should not happen with my code.

    If it still doesn't work correctly, please post a screenshot of your events.

    Thanks for trying to help, I solved it myself, turns out I was being dumb. I had a wait that was causing this.

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