Translations

Know another language? Translate this tutorial!

Stats

8K visitors
53.5K page views
386 translation visitors
1,085 translation page views

How to use the System 'Wait' actions

Favourite 77 favourites
Tutorial written by AshleyOriginally published on 22nd, August 2011 - 10 revisions

The Wait action in the System object waits a number of seconds before running the next action. The Wait for signal action works very similarly, but instead of a time delay waits until you use a corresponding Signal action. They remember all the picked objects so it works exactly like a normal event, just a bit later in time. During the wait, other events continues to run as normal.

For example, consider:

+ On spacebar pressed
-> Player: spawn a bullet
-> Audio: play 'bang' sound

If you hit spacebar, your bullets emerge with a bang immediately. If you add a Wait action, though:

+ On spacebar pressed
-> System: wait 1 second
-> Player: spawn a bullet
-> Audio: play 'bang' sound

If you hit spacebar, there's a one second delay, then the bullet emerges with a bang. If you tap spacebar twice quickly, it queues up twice, so two bullets are shot, each one second after you hit spacebar.

You can also use the wait action multiple times in an event. For example:

+ On start of layout
-> Text: set text to "Hello there!" & newline
-> System: wait 1 second
-> Text: append text "How are you?" & newline
-> System: wait 1 second
-> Text: append text "Nice to meet you!"

This event adds each message to the text object at one second intervals. Don't forget the rest of your events are running as normal while the waits are waiting. Any events can set up as many waits as they want at any time, and it all runs as scheduled.

Here's another example:

+ Every 1 second
-> Sprite: set invisible
-> System: wait 0.3 seconds
-> Sprite: set visible

The sprite flashes.

One more example:

+ Every 2 seconds
-> Enemy: spawn 'bullet'
-> System: wait 0.2 seconds
-> Enemy: spawn 'bullet'
-> System: wait 0.2 seconds
-> Enemy: spawn 'bullet'

Every 2 seconds, the enemy fires a salvo of three bullets, each 0.2 seconds apart.

If you're feeling super pro, you can schedule events in loops too:

+ On start of layout
+ Repeat 10 times
-> System: wait loopindex seconds
-> Text: append text "Time = " & time & newline

This one event will cause a new line to be added to the text object every one second for ten seconds. This is because the "Repeat 10 times" condition runs the actions ten times, and each run schedules a wait of a different length of time followed by adding a line of text. This spreads all the "append text" actions out over time.

Note: if you wait for a constant amount of time in a loop, like this:

+ On start of layout
+ Repeat 10 times
-> Wait 1 second
-> Append text "Time = " & time & newline

This may not do what you expect. When the first 'Wait' is reached, the loop continues to run (since the rest of the event sheet carries on independently of waits). So the loop completes instantly, scheduling ten 'Append' actions each after a one second delay. So after one second, all ten actions run at the same time. If this isn't what you want, either use the Every X seconds system condition, or use the loopindex based variant above.

Note about using 'Wait' in functions

Note that in a function call, if you use 'Wait' then the function has finished by the time the next action after the 'Wait' runs. This means the function parameters are no longer available. You could work around this by copying function parameters to a local variable.

For advanced users

The Wait action saves which objects are picked and cancels the current event. When the wait time has expired or it is signalled, the picked objects are restored as they were when the wait started (minus any objects that got destroyed), and the event is resumed from the action following the wait action. It continues to run any subevents as well. At any point if another wait action is encountered, the same save-picked-objects-and-wait process happens, so you can make different parts of an event run at different times.

One more trick: "Wait 0 seconds" postpones the following actions until the end of the event sheet.

Waiting for a signal just waits until you use the Signal action instead of a time delay. For example if you have an event that does Signal "Enter" when the Enter key is pressed, then Wait for signal "Enter" will wait until you next press Enter. This provides a useful alternative way to schedule events beyond simply waiting for time delays: you can make events wait until a meaningful event happens in the game. Apart from that it works identically to the Wait action, including that other events keep running while it waits (which also applies to loops that carry on to the next iterations even though the current iteration started waiting). There can be multiple waits for one signal, and they all resume the next time the Signal action is used.

Conclusion

This is really powerful feature. If you ever used Construct Classic, you should find it a much more elegant solution than the Function object's "call after delay". Scheduling things over time by events has always been a bit of a headache, so hopefully this makes it nice and simple!

Unlock your full gamedev potential

Upgrade to the Personal Edition of Construct 2, it has way more features and won't holding back from making money and using your full creativity like the free edition does. It's a one off payment and all Construct 2 editor updates are free for life!

View deals

Plus, it's got a lot of additional features that will help you save time and make more impressive games!

Congratulations on finishing this tutorial!

Did you learn a lot from it? Share it now with your friends!

Share and Copy this Tutorial

You are free to copy, distribute, transmit and adapt this work with correct attribution. Click for more info.

Comments

3
TheBen 3,009 rep

Useful, I suppose. Does everything in this tutorial apply to Construct Classic as well?

Tuesday, August 23, 2011 at 10:56:11 PM
7
Ashley 196.1k rep

Construct Classic doesn't have a Wait action, so no, not really.

Wednesday, August 24, 2011 at 1:26:16 AM
4
danny 6,018 rep

Nice addition Ashley!

Thursday, August 25, 2011 at 8:59:33 PM
2
gaboduarte 13.8k rep

Just used it on a small game-test I am making.
Oh eM Gee! Great addition!

Sunday, September 04, 2011 at 5:10:56 PM
3
Wronghands 4,630 rep

I know it's the advanced section but it'll help if you put a link to somewhere that explains what you mean by "SOL"

Monday, December 19, 2011 at 7:35:13 PM
1
Bigheti 17.1k rep

Cool...and very interesting!

Friday, January 13, 2012 at 7:11:25 PM
2
Geo 5,675 rep

This is important for my game, I need to know: after Wait, can the event resume in the middle of running other events? I mean, let's say I call wait (1 second). In the meantime other events are processed. After exactly 1 second has elapsed, the system is in the middle of executing some other actions in another event. Will these actions in the other running event be interrupted?

Tuesday, March 06, 2012 at 9:48:11 PM
2
Ashley 196.1k rep

@Geo - no, it will always resume waiting events at the end of the event sheet. It will never skip from another event half way through, that would cause lots of weird bugs!

Tuesday, March 06, 2012 at 10:48:57 PM
1
Geo 5,675 rep

That is perfect! Thanks Ashley.

Wednesday, March 07, 2012 at 7:15:19 AM
1
blackvikinggames 4,934 rep

Thank you very much!

Monday, March 19, 2012 at 1:39:39 AM
8
Potato 8,118 rep

SOL = Selected Object List
in case someone wondering what it means when they read this tutorial.

Monday, April 09, 2012 at 3:53:26 AM
2
joeykid6 4,001 rep

I just learned that 'wait' actions will queue if their event runs more than once. This may seem obvious, but I thought it was worth mentioning. If you are using a 'wait' action in an event triggered by a variable, make sure to set the variable to something new before the wait kicks in, not after. Otherwise you'll get a queue of 60 waits for every second you're waiting.

Monday, April 30, 2012 at 9:33:58 AM
1
Sylvain 6,609 rep

Thanks a lot for this tutorial. 'Wait' has no secret for me now ! (or I hope so :) )

Thursday, January 10, 2013 at 9:25:37 PM
1
creamcakes 2,426 rep

I wonder if you can help me, im currently in the middle of a project and im experiencing some difficulty. When my character is in a safe area everything is fine but if the character moves in the kill field there is a 5 second wait event before the character dies, but if the character moves back in the safe area i want this wait command to be canceled because the character dies regardless. Please help me and thank you for your time.

Thursday, February 07, 2013 at 12:53:33 PM
2
Phyvo 917 rep

what does SOL stand for?

Tuesday, February 12, 2013 at 4:13:08 PM

Leave a comment

Everyone is welcome to leave their thoughts! Register a new account or login.