Back to tutorial index

The joy of Wait()ing

In this tutorial, I'll talk about the waiting functions available in ACS.

Some of the less frequently used (as far as I can tell) and more underrated ACS functions, the usefulness of the waiting functions is not to be understated. If your ACS script involves a lot of moving sectors and Delay calls, you've probably spent a good amount of time manually calculating the tics needed for each instance of Delay and bashing your head against the wall with getting everything at least adequately synced up. Using a waiting function can significantly cut down on the need for manually calculating Delay durations.

As an example, the TagWait function, when called in a script after triggering a moving sector action, will tell the script that it should wait for the sector to finish its movement before executing any function calls that follow. The function takes a single argument, that being the tag of the sector to wait for.

A very simple but effective use case of the TagWait function is to insert it at the end of a script that triggers multiple moving sectors, such as lifts. Doing so will ensure that the script can't be reactivated until all of the moving sectors finish their moving actions, if the action in question is repeatable. I personally used the TagWait function to great effect in Gomorrah, as well as for a lift in MAP05 of A Piece of Hell. The switch that activates the lift in question is in front of the lift, effectively blocking it, and goes down with the lift. Another switch at the top of the lift lowers it again. By inserting TagWait functions for each sector tag after the Plat_DownByValue calls, I ensured that the lift couldn't be activated multiple times while it's still moving:

script 3 (void) // Elevator to second floor { Plat_DownByValue(5,32,70,25); Plat_DownByValue(8,32,70,25); Plat_DownByValue(6,32,140,12); TagWait(5); TagWait(6); TagWait(8); }


A similar use case can be found in Deliverance 2600, where I used TagWait to prevent the 3D floor bridge in the opening area from being "reversible" while it's moving:

script 2 (void) //Platform and bridges lower { if(getsectorceilingz(10,0,0) != 0) { delay(1); } else { floorandceiling_lowerbyvalue(10,8,128); floor_lowerbyvalue(11,8,128); tagwait(10); tagwait(11); } } script 3 (void) //Platform and bridges raise { if(getsectorceilingz(10,0,0) == 0) { delay(1); } else { floorandceiling_raisebyvalue(10,8,128); floor_raisebyvalue(11,8,128); tagwait(10); tagwait(11); } }


Similarly to TagWait, the ScriptWait, NamedScriptWait and PolyWait functions can be used to wait for numbered scripts, named scripts and polyobjects respectively. The ScriptWait function, for instance, will wait for the specified numbered script to stop running before executing following function calls. NamedScriptWait holds the same purpose for named scripts, and PolyWait will wait for a polyobject to finish its movement before executing further function calls.

That concludes this tutorial on the ACS waiting functions.