Event order logic question

0 favourites
  • 3 posts
From the Asset Store
100 items casual and logic games. All icons are of a high quality.
  • I have the following situation with event order

    <img src="http://dl.dropbox.com/u/37009800/Construct%202/Need%20Help/EL.png" border="0" />

    I would like to understand the difrence in event order and logic of execution in C2 (i know is from up to botom), but in this case (not working sheet) when you klick and 'active'=0 and 'c'=0 then it change them to 1 and in same event, I guess, check if 'active' is 1 and 'c' is 1 so it sets 'active' to 0 but not 'c' so it can't reset conditions ('active'=1, and 'c'=0 can't triger enything). Em i right? Or is it something else in question?

    I think that C2 need some nice basic tuts about event logic, I can't always grasp what's accualy happening.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hiya podpathos.

    The logic is "falling through" - events are executed one after another, top down to the bottom. The issue you have here is that subevents do not know when you are using them as a switch statement - which is what you're trying to do here. There is no implicit break after a subevent, so Construct just keeps on executing.

    Go through your event in question logically with the non-working version:

    On any click, C2 does the following comparison:

            if(active == 0 & c == 0) then (active = 1 & c = 1)

    Then C2 does the next comparison:

            if(active == 1 & c == 1) then (active = 0)

    But we just made that true with the last event! So this event will always execute - and active cannot equal 1.

    The solution to this can be what you posted as working - don't place events that are dependant on the outcome of other events below those events. OR you can use local variables. Have a global number, and test with each subevent that that number is 0. If it's not, it won't execute. If it is, execute the action and set the global number to 1. This guarantees only one event will ever execute in a subevent branch.

  • Thanks man, I see it all much clearer now.

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