Confused trigger behavior

0 favourites
  • 5 posts
  • DESCRIPTION

    This also happens in C3

    When the space bar is pressed, the trigger contained in the "else" is executed even though the initial condition is true, this means that the "else" must never be executed.

    CAPX

    https://www.dropbox.com/s/01b0vlphzmlrl88/bugTrigger.capx?dl=0

    CAPX Description

    The capx only has one sprite, the keyboard plugin and two conditions.

    STEPS TO REPRODUCE

    Press the spacebar and check how the sprite is located in X 400, this means that the trigger contained in the "else" was executed

    EXPECTED RESULT

    Only the trigger should be executed in the initial condition, the trigger in the "else" should not be executed.

    SYSTEM OS

    Win10 64b

    C2 Version

    259 64bits

  • If you replace the key pressed with key is down and trigger once you will solve the issue.

    I'm curious if this can be fixed or if it works as intended, triggers are an override type event so it may be summoning the else statement bellow. I'm glad you pointed this out.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • From the sdk manual:

    an event cannot contain two triggered conditions, and a trigger is always the first condition.

    This means you event(s) looks like that:

    -> Keyboard| On space pressed -> Sprite| set X to 0

    -> Keyboard| On space pressed -> Sprite| set X to 400

    The rest will be ignored and x will first set to 0 then to 400.

  • You mean that the two triggers will be executed and the last one to do it is x 400.

    But this solves the problem.

    What does it mean then?

    imgur.com/sc71THv

  • Closing as won't fix. This is a pretty obscure case. A trigger in a sub-event is essentially the same as having the trigger at the top, and all events that are above it actually beneath it as sub-events. Since having an "Else" as a lone sub-event to a trigger isn't valid, this does't work. (Internally when the trigger fires, it runs through all the events above it and checks if they're true first before running the event. Since "Else" means "the previous event did not run", asking when a trigger fires does not make any sense since it did not run the previous event at all, so it has no value for true/false, so the else defaults to returning false.)

    The workaround is straightforward: rearrange the events to put the trigger at the top.

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