event running order

Get help using Construct 2

Post » Thu Jul 28, 2016 3:44 am

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.
B
58
S
18
G
13
Posts: 447
Reputation: 10,735

Post » Thu Jul 28, 2016 4:57 am

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.
Mistakes were made.
B
52
S
26
G
108
Posts: 1,606
Reputation: 61,133

Post » Thu Jul 28, 2016 7:53 am

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"?
B
58
S
18
G
13
Posts: 447
Reputation: 10,735

Post » Thu Jul 28, 2016 9:34 am

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.
Mistakes were made.
B
52
S
26
G
108
Posts: 1,606
Reputation: 61,133

Post » Thu Jul 28, 2016 1:30 pm

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
B
42
S
17
G
17
Posts: 2,247
Reputation: 17,461

Post » Thu Jul 28, 2016 1:40 pm

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.
ImageImageImage
B
27
S
16
G
79
Posts: 1,013
Reputation: 44,245

Post » Thu Jul 28, 2016 1:44 pm

Ok thank you all for the replies.

@backendfreak
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?
B
58
S
18
G
13
Posts: 447
Reputation: 10,735

Post » Thu Jul 28, 2016 1:48 pm

@whiteclaws interesting. So what you say the events do not wait on each other after all. :P

EDIT:
I tried to add wait 0 after every suitable event but it just effed up the whole thing. Well.
Last edited by helena on Thu Jul 28, 2016 2:03 pm, edited 1 time in total.
B
58
S
18
G
13
Posts: 447
Reputation: 10,735

Post » Thu Jul 28, 2016 2:03 pm

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)
B
42
S
17
G
17
Posts: 2,247
Reputation: 17,461

Post » Thu Jul 28, 2016 2:18 pm

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. ;)
B
58
S
18
G
13
Posts: 447
Reputation: 10,735

Next

Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, ItsAstro, kellehk and 32 guests