ACS_ExecuteAlways

From ZDoom Wiki
Jump to: navigation, search

226:ACS_ExecuteAlways (script, map, s_arg1, s_arg2, s_arg3)


  • script: Script to execute
  • map: Map which contains the script
  • s_arg1: First argument passed to the script
  • s_arg2: Second argument passed to the script
  • s_arg3: Third argument passed to the script

Usage

Like ACS_Execute, this special starts a script. However, it will allow multiple instances of a script to run simultaneously. The downside is that any scripts started with this special cannot be suspended or terminated with ACS_Suspend or ACS_Terminate, respectively.

A common use for this special is in multiplayer games, when more than one player may need to run a script at the same time. A script executed with ACS_Execute by one player would not be triggered by another if they attempt to trigger it while it is still running. In fact, the script does not run at all. ACS_ExecuteAlways can be used to prevent this problem by being able to run multiple instances at once, one for each player.

Examples

This example shows how ACS_ExecuteAlways can be an advantage over ACS_Execute. The script regenerates health for a player while they remain within the sector it is activated from.

int InSector[8];

script 10 (void)
{
     InSector[PlayerNumber()] = TRUE;

     while (InSector[PlayerNumber()]) {
          GiveInventory("HealthBonus", 1);
          ThingSound(0, "special/regen", 127);
          delay(15);
     }
}
            
script 11 (void)
{
     InSector[PlayerNumber()] = FALSE;
}

Script 10 is called by an "Actor Enters Sector" thing using ACS_ExecuteAlways. It sets a flag variable to true and loops until the flag is false. Script 11 is called by an "Actor Leaves Sector" thing, and unsets the flag variable. The flag system is necessary because the script cannot be ended simply by using ACS_Terminate on it.

Because this script is using ACS_ExecuteAlways instead of ACS_Execute, it is possible for up to eight copies of the script to be active at once — one for each player in the game.

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

External links