ScriptWait

From ZDoom Wiki
Jump to navigation Jump to search

void ScriptWait (int script);

Usage

Delays the script it is contained within until the script specified by script has completed execution. If the specified script is not running, this command will wait until it has run. For named scripts, use NamedScriptWait.

Parameters

  • script: The script number to wait for.

Examples

The advantage of ScriptWait is that it can hold a once-only script. Say there was a script which is to be run only once to open a door (for example it activates when the player destroys a control panel which can only be done once), but the map requires the door to be unlocked previously to this. In the event that the door is still locked, ScriptWait can be used to hold the once-only script until the script that unlocks the door has started and finished.

An example implementation of this code follows. It is rather lengthy, but fairly straightforward.

bool locked = TRUE;
script 1 (int sector)
{
    if (locked)
    {
        Print (s:"Security access required!");
        ScriptWait (2);
    }

    Door_Open (sector, 20);
}
 
script 2 (int count)
{
    while (count > 0)
    {
        HudMessage (i:count--; HUDMSG_PLAIN, 1,
            CR_RED, 0.05, 0.95, 1.0);
        Delay (1);
    }

    HudMessage (s:"Verified!"; HUDMSG_PLAIN, 1,
        CR_GOLD, 0.05, 0.95, 1.0);
	
    locked = FALSE;
}

The first script is the once-only script. If the door is locked, it tells the user and waits for the unlock script to run and finish. After that, or if the door was already unlocked, the door opens.

The second script takes a parameter, which is the amount of frames to count before unlocking. Note that count is displayed as count--, where the two minus signs are the decrement operator. After the count is up, the door is unlocked.

Script functions
ACS_Execute ACS_NamedExecute
ACS_ExecuteWait ACS_NamedExecuteWait
ACS_ExecuteAlways ACS_NamedExecuteAlways
ACS_ExecuteWithResult ACS_NamedExecuteWithResult
ACS_LockedExecute ACS_NamedLockedExecute
ACS_LockedExecuteDoor ACS_NamedLockedExecuteDoor
ACS_Suspend ACS_NamedSuspend
ACS_Terminate ACS_NamedTerminate
ScriptWait NamedScriptWait
FS_Execute UsePuzzleItem