ACS_ExecuteAlways

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 eight (or more) copies of the script to be active at once  one for each player in the game.

Script functions
ACS_ExecuteACS_NamedExecute
ACS_ExecuteWaitACS_NamedExecuteWait
ACS_ExecuteAlwaysACS_NamedExecuteAlways
ACS_ExecuteWithResultACS_NamedExecuteWithResult
ACS_LockedExecuteACS_NamedLockedExecute
ACS_LockedExecuteDoorACS_NamedLockedExecuteDoor
ACS_SuspendACS_NamedSuspend
ACS_TerminateACS_NamedTerminate
ScriptWaitNamedScriptWait
FS_ExecuteUsePuzzleItem
This article is issued from Zdoom. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.