event running order

0 favourites
  • 15 posts
From the Asset Store
Full game Construct 2 and Construct 3 to post on Google Play
  • Long time no see. I am trying to refresh my memory.

    If I recall it correct the events are gone through top to bottom, that is known.

    But I also recall that the events will go down to next line even if the previous event line isn't finished, right?

    How can I do to ensure that the events are finished before proceeding?

    I am trying to tackle my beast of game now that I have some time off.. Array driven grid movement of 500-1000 characters per screen, refreshing every 0.2 second. I got bug that I *think* is that the next "round" of 0.2 second starts before the old one was finished.

  • Only the "Wait" actions will allow events to complete out of order.

    https://www.scirra.com/tutorials/56/how ... ait-action

    To keep an event with "Wait" in it from activating every tick, add a "state flag"(a variable) that you check as a condition. Upon running the event, toggle the state flag to active, and after the wait action, toggle it back to finished. Have the event only run on the condition that the state is finished.

  • Ah so the events will run in succession, even with function calls with excessive loops within the "every 0.2 second" event? As long it has no "Wait"?

  • Loops should run to completion before the next frame is rendered, as far as I know. Not completely sure if functions have a special timing for when they are run, I assume the function just gets inserted wherever it was called.

  • Wait 0, it is specially designed to wait 'till all the last events ran before proceeding, you can put all the events into a function and put wait 0 after that function and It'll wait 'till the function ran completely 'till proceeding

    You can check out my tutorial on the subject:

    https://www.scirra.com/tutorials/510/ad ... ct2-offers

  • If you trigger a function before any other event, engine will first execute the function and then go back to your events. So it will not run the function asynchronously. Otherwise we would have really big problems with building our apps. But if you use groups then there's a different story. Unlike triggering the function, toggling a group takes one tick. So if you activate a particular group, code which is under this group will be triggered next tick.

  • Ok thank you all for the replies.

    I wonder, the groups. I use groups but just for the cosmetic reason, to make it look better in the events page.

    I do not have any runtime actions about groups. So the events inside group should simply be run top to bottom, right?

  • Whiteclaws interesting. So what you say the events do not wait on each other after all.

    EDIT:

    I tried to add wait 0 after every suitable event but it just effed up the whole thing. Well.

  • Well, it depends really, an event that destroys an object will ask the program to destroy it, but the runtime won't destroy the object immediately, and if you are for example, counting instances the next tick, if can mess up all of your logic. Just add a wait 0 after the Destroy Object, and the program will wait 'till that object us destroyed to keep going,

    That's just one example, I found many possibilities with Wait 0. (It's also confirmed by Ashley as a feature)

  • Interesting. Ok!

    I see now there are a consistent bug with one of the player actions that I thought I did not have earlier. I wonder if it could have been caused by new versions of C2 (I haven't touched the gameplay code for more than 1 year, or even 2 years), I have tested many versions of the game. Or was I that negligent. haha.

    I wish I had someone with fresh eyes and better logic to look at my game but at same not uploading it to this forum.

  • Whoops. Looks like the event that should be sub-event wasn't sub-evented so to say.

  • Ok thank you all for the replies.

    I wonder, the groups. I use groups but just for the cosmetic reason, to make it look better in the events page.

    I do not have any runtime actions about groups. So the events inside group should simply be run top to bottom, right?

    If you're not toggling the groups then your code runs top > bottom all the time. Active groups do not affect anything, no worries .

  • Good to know. Now I have solved the bug anyway so onward to the other bugs!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • But if you use groups then there's a different story. Unlike triggering the function, toggling a group takes one tick. So if you activate a particular group, code which is under this group will be triggered next tick.

    That's not exactly correct. Toggling a group is instant, so if you activate a group before the group in the event sheet it will run the same tick, but if you activate it after the group in the event sheet the group won't run until the next tick.

  • Yes, that's precise. Thanks Also worth to mention that it is the same with toggling groups placed in separate event sheets. If you include event sheet below "toggle action" it will take effect in the same frame, if above then next tick. It's common that event sheets are always included at the top (then toggling always takes effect next frame), but it actually matters where you include them.

    Not sure which one is respected if you include the same event sheet multiple times in various places but I guess it's the first one.

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