Trigger Once for Each Instance Who Meets Certain Criteria

0 favourites
  • 6 posts
From the Asset Store
Change the size and position of everything without calculating anything!
  • I am having a problem. In my game, I am attempting to implement a system wherein if an enemy's "Shield" value is reduced to zero, three things should happen:

    1. The enemy's boolean "Break" is set to "True"

    2. The enemy's "Physics" behavior is enabled

    3. The enemy is struck by an impulse

    The set up is like this:

    Enemy.Shield=0|Set "Break" to true

    _______________(Separate Event, not a sub-event)__________________

    Enemy=IsBreak|Set "Physics" enabled

    Apply impulse (x) to Enemy

    Obviously, the problem this created was that it will run the event indefinitely. So my thought was that I could circumvent this with the "Trigger Once" condition, but as it turns out, if I have more than one instance of the same Enemy, only the first one that enters "Break" will work properly if I add "Trigger Once" to either the "Enemy.Shield=0" event or "Enemy=IsBreak". How can I arrange my events so that it works for each enemy individually just once?

    Thank you.

  • You can use a variable to Catch once it has triggered one time.

    I have a quick video walk through that explains it for you:

    youtu.be/h2xM1Y4C-Mo

    For yours specifically you want to set the catch on each enemy.

    Have a nice night ^^

  • Wow! Thanks for making an entire video just for me! That's awesome. So if I understand correctly... well, do I need a global variable? Local? Instance variable? As the game is something of an RPG, I just have one layout for every conceivable battle screen (with the exception of some boss fights), so it would need to work for any conceivable enemy. Would I use a family instance variable? (In my actual project, the enemies are part of a Family). Let me know, thanks. I'll try and work with your video walk-through, though and see if I can't come up with the answer myself.

  • Works with an instance variable. Thanks a lot!

  • You are very welcome - also a variable run down:

    You generally want to keep each variable as secluded or remote as possible while still able to perform its goal 100% of the time.

    Instance variables will be attached to your Sprite and they will go away if you ever destroy that sprite

    Local variable works only inside of whatever part of code its created - if you're using an if statement to compare numbers and can set a local variable with the higher of the 2 and then that variable will vanish once you are out of the if

    Global is accessible everywhere

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • This is really helpful, and something that I was wondering about.

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