How triggers run
A trigger is a list of up to 16 conditions and up to 64 actions, and the players it runs for. When every condition holds, the game carries out the actions in order. A trigger that should run straight away has Always as its condition; a trigger with no conditions at all runs straight away too.
The trigger cycle#
The game does not check triggers continuously. It goes through them in passes, one every 31 game frames: 1.3 seconds at Fastest, 2.1 seconds at Normal. The first pass is on the game's second frame, so an Always trigger runs at once. A pass comes after that frame's units have moved, fought and died, so a unit killed in a frame already counts in that frame's pass.
In a pass the game takes the players in the game in order, Player 1 to Player 8, and for each goes through that player's triggers top to bottom, in the order of the list. It asks a trigger's conditions in order and stops at the first false one, so the conditions after it are not even asked. If they all hold, it carries out the actions in order. What one trigger does is seen by every trigger after it in the same pass, with one exception for counts of units (see Counting units).
Two things bring the next pass forward to the very next frame, for every player: a Wait running out, and the countdown timer reaching 0.
Game speed does not change the 31-frame cycle or game time: a game second is 16 frames at every speed, for Elapsed Time and the countdown alike. It changes only how long a Wait lasts (Waits).
Hyper triggers#
A Wait of 0 runs out on the frame after it starts, and the pass it brings forward comes the frame after that. So the fastest the game goes through the triggers is once every 2 frames. It never manages every frame.
Hyper triggers use this: two or three preserved triggers of 62 or 63 Wait(0) actions each, owned by one player. Each pass starts another of their Waits, so the passes keep coming every 2 frames. A slow pass, 31 frames after the last, comes only when none of them has a Wait to start, and with that many Waits it comes so rarely that it does not matter in practice.
The cycle is shared, so one player's hyper triggers speed up every player's triggers. A computer player can carry them. The waits must be one frame long or less: 42 milliseconds at Fastest.
Who a trigger runs for#
A trigger is owned by one or more of the players and groups: a player, a force, or All Players. A trigger owned by a group runs separately for each player in it, as if each had a copy of their own. Its conditions are checked and its actions carried out once per player, and inside it Current Player means whichever player that copy is running for.
The copies are handed out when the game loads the map, and only to players in the game: human and computer players, and rescuable and neutral slots, which run their triggers like anyone else. Only these owners get copies:
- Players 1 to 8;
- Force 1 to Force 4;
- All Players.
A trigger owned only by anything else (Players 9 to 12, Current Player, Foes, Allies, Neutral Players, Non-Allied Victory Players, None or the Unused groups) is dropped when the game loads and never runs. Other editors let you tick those owners, but the game ignores them. scmJS's Trigger Editor offers only the owners above; when a map's trigger already has another ticked, it is shown with a note so you can clear it.
Only Use Map Settings games read a map's triggers at all. Melee and the other game types
run triggers built into the game. (See TRIG in the CHK reference.)
Each owner gets its own copies, so a player reached twice, as with both "Player 1" and "Force 1" ticked, has two copies of the trigger and runs it twice in every pass.
A player who is defeated, or leaves, stops running triggers. In a single-player game a player who has won keeps running them until the victory screen stops the game.
Once, or every time#
A trigger runs once for each player it runs for and is then finished, unless it carries Preserve Trigger. Then, once its actions are done, the game asks its conditions again on the next pass. A preserved trigger whose conditions stay true keeps firing: one that adds a mineral adds one each pass. Preserve Trigger works wherever it stands in the list, even after a Wait: the game looks for it when the actions end.
While a trigger is part way through its actions, held at a Wait, the game does not ask its conditions again. On each pass it carries on from the action it stopped at.
Waits#
Each player has one wait slot. A Wait takes it and holds the rest of its trigger until its time has passed. While the slot is taken, another trigger of that player that reaches a Wait stops there without starting its time, and tries again on each pass until it finds the slot free. The player's triggers with no Wait in their way keep running every pass, and every player's slot is their own. A Transmission for a person, and Center View in a single-player game, take the same slot.
A Wait's time is in milliseconds of the game's speed, close to real time, not game time. Each frame takes a fixed number of milliseconds at each speed, the Wait lasts its time in frames, rounded up and at least one, and the trigger goes on in the pass on the frame after:
| Speed | Milliseconds a frame | Wait(0) goes on after | Wait(1000) goes on after |
|---|---|---|---|
| Fastest | 42 | 2 frames | 25 frames |
| Faster | 48 | 2 frames | 22 frames |
| Fast | 56 | 2 frames | 19 frames |
| Normal | 67 | 2 frames | 16 frames |
| Slow | 83 | 2 frames | 14 frames |
| Slower | 111 | 2 frames | 11 frames |
| Slowest | 167 | 2 frames | 7 frames |
A Wait of 4,294,967,295 never runs out, and takes that player's wait slot for the rest of the game.
On a map with hyper triggers, a Wait in another trigger below them in the list hardly ever gets the slot: it can start only in the one slow pass. A Wait above them takes the slot first, and while it runs no hyper Wait can start, so the passes fall back to every 31 frames until it runs out. Check Map points this out.
Timers with a death counter#
A death count of a unit type the map never uses makes a timer that needs no Wait, so it never holds up the player's other triggers or the hyper triggers. One preserved trigger adds 1 to the count every pass, and other triggers act when it reaches a number:
Trigger("Player 1"){
Conditions:
Always();
Actions:
Set Deaths("Player 1", "Cave (Unused)", Add, 1);
Preserve Trigger();
}
Trigger("Player 1"){
Conditions:
Deaths("Player 1", "Cave (Unused)", At least, 120);
Actions:
Create Unit("Player 8", "Zerg Zergling", 6, "Spawn");
Set Deaths("Player 1", "Cave (Unused)", Set To, 0);
Preserve Trigger();
}
The count goes up once per pass, so its speed depends on how often the passes come: one every 31 frames normally, or one every 2 frames with hyper triggers, which is about 12 a second at Fastest. With hyper triggers, the second trigger above sends a wave about every ten seconds. Setting the count back to 0 starts the timer again. The trigger's owner has to be in the game, or neither trigger runs.
Single player and multiplayer#
The game runs every player's triggers on every machine, and only what reaches the screen is limited to the player the trigger runs for: text, sounds, portraits, pings and the view. A few actions behave differently in a single-player game:
| Action | In a single-player game | In a multiplayer game |
|---|---|---|
| Transmission, for a person | holds the trigger until the portrait has finished talking | holds the trigger for its duration, in milliseconds of game speed |
| Center View, for a person | scrolls the screen and holds the trigger until it gets there | jumps the screen at once and does not hold |
| Pause Game and Unpause Game | pause and unpause, for a person's trigger | nothing |
| The Esc key | skips the person's running triggers through their Waits, transmissions, text and sounds, unless Disable Debug Mode protects them | nothing |
| A player who gets a result | keeps their triggers | loses their whole trigger list at once, winners and losers alike |
For a computer, rescuable or neutral player, Transmission, Center View, Pause Game and the other actions that touch the screen do nothing at all, and do not hold the trigger.
Winning and losing#
Victory, Defeat and Draw give the player the trigger runs for a result, and the game settles the results at the end of each pass:
- When any player won or drew in the pass, every other player still in the game with no result of their own is defeated.
- When every player in the game won or drew in the same pass, they all get a draw.
- The first result a player gets stays. A Defeat or Draw that comes after a Victory for the same player in the same pass waits, and by the next pass the player has already won.
So in a single-player game, a Victory for the person ends the game for the computers too, and a Draw is a draw only when everyone draws.
Counting units#
Command and Bring, and the Most and Least conditions built on them, count units in ways that are easy to trip over:
- At most counts differently from At least and Exactly. At least and Exactly count finished units. At most counts every unit that exists, finished or not: a building going up, an egg or cocoon (as Men), a unit whose training has begun. So the standard melee defeat rule, Command(Current Player, Buildings, At most, 0), does not defeat a player whose only building is still being built.
- Units aboard a transport or bunker count for Bring only with At least and Exactly, at the place of what carries them, and so do the interceptors or scarabs in a carrier or reaver and a power-up a worker carries. With At most, Bring does not count them.
- A unit is in a location when its box touches it, on the levels the location covers. Ground units count by the ground under them; air units by the air bits of the location's elevation settings.
- Hallucinations never count, in Command or Bring, and neither do turrets.
- The counts are taken once per pass. The first Command of a pass counts every player's units, and every later Command in that pass, for any player, reads the same counts.
So a unit made by Create Unit or handed over by Give Units to Player later in the pass is invisible to Command until the next pass. These take a new count straight away:
- Kill Unit and Kill Unit At Location;
- Remove Unit and Remove Unit At Location;
- Move Unit and Move Location;
- a Bring condition.
Bring keeps a count of its own for one location, with the same blind spot. It counts again when another location is asked about, and after the same actions.
Deaths and kills#
A unit's death counts only when it dies in the game: shot, killed by a spell, or consumed. Then its owner's death count for its type goes up by one, and the killer's kills and score, if the killer is another player still in the game. Killing your own units counts nothing as a kill; killing an ally's counts.
Kill Unit, Remove Unit and their At Location forms count nothing at all: no death, no kill, no score. Neither does a hallucination dying.
The unit classes are counted apart. Deaths of Men, Buildings and Factories read the game's own counts of men, buildings and factories lost, which go up with each real death; Deaths of Any unit reads men and buildings lost together. They are not the sum of the per-type counts: Set Deaths on a Marine does not change Deaths of Men, while Set Deaths of Men changes the lost count itself.
Disabled conditions and actions#
A condition or action can be disabled without deleting it (a flag in its record). The game
skips it: a disabled condition does not count, and a disabled action is not carried out.
In text, a disabled line starts with ;.
Condition and action numbers the game does not have#
Conditions are numbered up to 23, actions up to 59 and briefing actions up to 9. StarCraft 1.16.1 does not check the number: when a trigger reaches a condition or action past the end, the game crashes. This was seen for a condition; for actions and briefing actions it is read from the game's code. Remastered checks: an unknown condition counts as false, so the trigger does not run, and an unknown action is skipped. The editor keeps such a record as it is, and Check Map reports it.
In StarCraft: Remastered#
Remastered's own code for running triggers has been read: how it goes through a trigger's conditions and actions, the trigger flag 0x02, how it settles results at the end of a pass, Victory, Defeat and Draw, and the conditions and actions named below. Those work as in 1.16.1, with these differences:
- An unknown condition or action number does not crash it (see above).
- A Map Revealer made by Create Unit stays. 1.16.1 creates it and removes it straight away as unplaceable. (Found playing Remastered.)
- Play WAV plays Ogg Vorbis sounds as well as WAV, in a Brood War map as in a Remastered one. 1.16.1 plays only WAV. (Found playing Remastered.)
- A map whose triggers use EUD values makes Remastered run its triggers in an EUD mode, where Deaths conditions and Set Deaths actions reach the game's memory.
These were read in its code and also played, with the same result as in 1.16.1: Create Unit makes nothing for Player 12, Set Deaths for Player 10 writes nothing in a map without EUD triggers, and Bring finds nothing in a location stored inverted.
Two parts were not read: how Remastered hands out the copies of the triggers when the map loads, which is in a scrambled part of its code, and the timing of the passes. For those, and for the actions not named here, the page describes 1.16.1.