Delay

From ZDoom Wiki
Jump to navigation Jump to search

void Delay (int tics);

Usage

Delays the script for the specified amount of time.

Parameters

  • tics: The amount of time to wait in tics.

Examples

Delay is a very common command. A useful application of it is to prevent infinite loops and the consequential “Runaway script x terminated” error. For example:

script 1 ENTER
{
    int health;
    while (TRUE)
    {
        health = GetActorProperty (0, APROP_HEALTH);
        Print (s:"You have ", d:health, s:" health!");
    }
}

This script will cause a runaway error because in will try to tell the player their health endlessly in a single tic without stopping. Adding a slight delay will result in the desired effect, a pointless health update that lasts forever, telling the player their own health.

script 1 ENTER
{
    int health;
    while (TRUE)
    {
        health = GetActorProperty (0, APROP_HEALTH);
        Print (s:"You have ", d:health, s:" health!");
        Delay (1); // Wait for next frame
    }
}

The other obvious use is to delay events in a script. For example, the behavior of the door that is used in the trap for the first key in E1M6 of Doom can be simulated with a script like this:

script 12 (int sector, int speed, int seconds)
{     
    Door_Close (sector, speed);
    Delay (35*seconds);
    Door_Open (sector, speed);
}

Although this behavior can be achieved using Door_CloseWaitOpen anyway.