Unexpected "Trigger Once" behavior?

0 favourites
  • 3 posts
  • I'm having trouble understanding why "Trigger Once" is not working as expected in this context (see attachment). I'm not looking for workarounds, I'm simply trying to understand why it's doing this.

    The Code

    I have an object "Sprite" with a variable called "Color". Every second I destroy all existing "Sprite" objects and then create two new ones - one with Color explicitly set to 0, and the other with Color set to 1. After that, based on the value of Color, I set the animation of each "Sprite" object to either "Color0" or "Color1".

    Expected Behavior

    Every second, I would expect to see one yellow "Sprite" and one blue "Sprite". This is because the "Color = 1" condition for the newly created sprite has never run in the previous tick. It may have run for a previous object, but not for the newly created one.

    Actual Behavior

    After the first round of creation, both sprites end up being yellow. This is presumably because "Trigger Once' doesn't care about which object it is firing for, it merely checks to see if the same event happened in a previous tick. But I could be missing something.

    Exactly what's going on here? Can someone break it down for me?


  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yeah - trigger once only cares if the condition was true or false last tick. It doesn't matter what objects the condition is true for.

    Your event 3, for example, will fire once when there is any Sprite with Color = 1, and then it won't run again until there is at least one tick where there is no Sprite with Color = 1.

    In this case there is always a Sprite with Color = 1 so the event never runs again after the first time.

  • thats right, tirgger once...runs once, and it will run again until there is some kind of change on the variables or coditions....

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