scmJS docs

Writing triggers

A trigger is one call:

trigger(AllPlayers, [
  bring(CurrentPlayer, units.AnyUnit, locations.Beacon, ">=", 1),
], [
  displayText("You found it!"),
  preserve(),
]);

trigger(players, conditions, actions, options?) records one trigger:

The order of the trigger() calls is the order of the triggers in the map.

Conditions and actions#

Every condition and action the game has is a function named after StarEdit's name for it, in camel case: bring, deaths, command, accumulate, elapsedTime, createUnit, displayText, setResources, moveUnit, order, runAiScript, victory. The one exception is the Switch condition, which is switchIs, because switch is a reserved word.

The arguments come in the order the Trigger Editor shows them. Where the Trigger Editor offers a list, the argument is a short word:

The full list is in the Reference. StarEdit's own labels, such as "At least", work too. Hover over any function in the editor to see its arguments.

not(condition) is the opposite of a condition, where one condition can say it: not(bring(…, ">=", 1)) is "at most 0".

Names from the map#

Units, locations and switches are named the way the map names them:

The editor checks the names as you type. A location passed where a unit belongs is an error, and so is a name the map no longer has.

Many triggers from a little code#

The script runs when it is applied, and everything TypeScript offers is available at that moment. A loop makes the same trigger for several players, a function returns a list of actions, a table holds the numbers, and a template string builds the text:

function reinforce(p: Player) {
  return trigger(p, [deaths(p, units.TerranMarine, ">=", 10)], [
    createUnit(p, units.TerranSiegeTankTankMode, 1, locations.Spawn),
    setDeaths(p, units.TerranMarine, "subtract", 10),
    displayText("Reinforcements have arrived."),
  ], { preserve: true });
}

for (const p of [P1, P2, P3, P4]) reinforce(p);

Nested lists are flattened, and false, null and undefined entries are skipped. A helper can return a list of actions, and a condition can be written hardMode && bring(…).

A condition is a value here: the game tests it later, when the map is played. So if (bring(…)) outside a program does not do what it looks like, and the editor says so. The test belongs in a trigger's conditions, or in an if inside a program.

Several files#

A script can have several files. import { x } from "./name" brings in another file of the map's script; nothing else can be imported. The library is available everywhere without an import, and also as the module "trigscript" for anyone who prefers import { trigger, bring } from "trigscript".

Hyper triggers#

hyperTriggers(P8) anywhere in the script adds the usual three preserved triggers of sixty-two waits, so that the game goes through the trigger list every 2 frames instead of every 31 (Hyper triggers). Give them to a player whose other triggers never wait, usually a computer slot: each player has one wait slot, and the hyper triggers keep it busy (Waits). A map with a program does not need them, because its build already makes the list run every frame. The build leaves hyper triggers out, both the script's and the map's own, and says so in a notice. It does the same for a trigger owned by a player group the game runs no list for (Players 9 to 12, Foes, Allies, Neutral, Non-Allied Victory Players).

scmJS 0.18.0 · Generated from the repository. The source is under the MIT license, which does not cover what ATTRIBUTION.md lists. StarCraft and Brood War are trademarks of Blizzard Entertainment; this project ships none of their data.