scmJS docs

Reference

Terms#

Term Meaning
Frame One step of the game. 24 a second at Fastest.
Pass One time the game goes through the trigger list: every 31 frames, every 2 with hyper triggers, every frame in a map with a program.
Game second 16 frames, at every game speed. What Elapsed Time and the countdown timer count.
Wait slot Each player has one. A Wait takes it, and the player's other Waits wait for it.
Apply Run the script and put its triggers into the map's trigger list.
Block The run of triggers in the list that the script made.
Build Turn the programs into the saved map. Only a script with programs is built.
Per-player program A program owned by several players, run for each with its own variables.

Triggers#

trigger(players, conditions, actions, options?) One trigger. players is a player or a list; up to 16 conditions and 64 actions.
{ preserve, disabled, ignoreGameEnd, ignoreDisplay, conditionsMet, paused, waitSkipDisabled, flags } The options: each trigger flag by name, and flags for raw bits.
preserve() The same as { preserve: true }, as an action.
not(condition) The opposite condition. "Exactly n" has none, and is an error.
disabled(item) The condition or action kept in the trigger but switched off.
hyperTriggers(owner?) The three triggers that make the list run every 2 frames.
condition(type, …), action(type, …) A record by raw type number, for anything the tables do not know.
memory(address, comparison, value), setMemory(address, modifier, value) EUD: a value in the game's memory, through the deaths table.

not() flips a comparison or a switch test, and turns always() into never().

Argument words#

StarEdit's labels work too.

Argument Words
Comparison ">=", "<=", "=="
Modifier "set", "add", "subtract"
Switch state "set", "cleared"
Switch action "set", "clear", "toggle", "randomize"
Resource "ore", "gas", "oreAndGas"
Score "total", "units", "buildings", "unitsAndBuildings", "kills", "razings", "killsAndRazings", "custom"
Order "move", "patrol", "attack"
Alliance "enemy", "ally", "alliedVictory"
Unit state (doodads, invincibility) "enable", "disable", "toggle"
Count A number, or "All"

displayText(text) always displays; displayText(text, false) follows the player's subtitle setting.

Names#

P1 … P12, CurrentPlayer, AllPlayers Constants.
players. Every player group: Force1 … Force4 (and the force's own name), Foes, Allies, Neutral, NonAlliedVictory, and the twelve players.
units. Every unit type by name as an identifier (TerranMarine) or a string (units["Terran Marine"]), and by the map's custom names. AnyUnit, Men, Buildings, Factories. With a mod's data set, the mod's names (Terran_Mason).
locations. The map's locations by name; Anywhere and NoLocation.
switches. Switch1 … Switch256, and any name the map sets.
aiScripts. The AI scripts by StarEdit name; a four-letter code as a string works too.
weapons., upgrades., techs. The game's weapons, upgrades and technologies, for stats().
colors. The player colours.
A number Accepted wherever a name is: an EUD player, an unlisted unit id.

Inside a program#

Each row links to where the TrigScript language guide explains it.

program(body, options?) Code that runs in the game. Options: owner (a player, AllPlayers, a force or a list) and name. Owners
game(fn) A function that runs in the game, for programs to call. It can live in any file and be imported. Functions in other files
let n = 0, let f = false, let s = "", let u: Unit | null = null, let p = { … } A number, a boolean, a text, a unit, a record. Variables
u8, u16, u32, fixed Numbers never below zero, and a number with a fraction. Whole numbers, fractions
u32(x), i32(x) The same 32 bits read the other way, where a u32 meets a plain number.
Math.sqrt, Math.hypot, Math.sin, Math.cos, Math.atan2, … Fixed numbers. Math.min, max, abs, floor and clamp(x, lo, hi) work on whole ones.
number[], string[], Unit[], { … }[], number[][] Arrays. One that is pushed to grows. Arrays
forEach, some, every, find, findIndex, reduce, map, filter, sort, reverse Array methods that take a function, on arrays and on units (unitsOf(P1).filter(…)). The methods
push, pop, shift, unshift, splice, slice, concat, join, toSorted, Array.from, [...xs] Growing, cutting and copying arrays.
Record<K, V>, Map<K, V>, Set<K> Tables keyed by an id of the game, by any number, or by units. Tables
class, extends, get / set, static, instanceof Classes, in the program or at the top of any file. Classes
const f = (x: number) => …, return () => … Functions kept as values, and closures. Functions as values
try, catch, finally, throw new Error(…) Errors. One nothing catches is shown in red in the game. Errors
shared(value) In a per-player program, one value for all the players.
sleep(duration), await sleep(…), await nextFrame(), await until(…) Pause the program. frames(n), seconds(n), minutes(n) make a duration. Waiting
start(f()), t.cancel(), Promise.all, Promise.race Tasks that run beside the program. Tasks
wait(ms) The game's own Wait, which uses the player's wait slot. Prefer sleep.
rose(condition), once(condition) True on the frame the condition becomes true; true the first time only.
random(), random(n) A coin toss; a whole number from 0 to n − 1.
deaths(p, unit), bring(p, unit, location), score(p, kind), … A comparing condition without its comparison and amount reads the number. Reading the game
minerals(p), gas(p), resources(p, kind), countUnits(p, unit, location?), kills(p, unit), countdown(), elapsed() Reads by plainer names.
race(p), slot(p), isHuman(p), hasLeft(p), supply(p, of?) The player.
unitsAt(location, filter?), unitsOf(player, filter?), allUnits(filter?) The units a for…of runs over. Units
first(filter?), nearest(type, location, filter?), randomUnit(filter?) One unit, or null.
u.hp, u.shields, u.energy, u.kills, u.cooldown, u.buildTime, u.stim …, u.invincible Read and written. u.hp = 0 kills. A unit's fields
u.maxHp, u.owner, u.type, u.x, u.y, u.speed, u.burrowed, u.cloaked, u.underAttack, u.inTransport, u.orderTarget, u.orderTargetX, u.orderTargetY, u.orderState, u.queuedOrders, u.acidSpores, u.opticalFlare, a.distanceTo(b) Read only.
u.order(kind, location), u.gather(target), u.cast(tech, target), u.stop(), u.give(player), u.kill(), u.remove(), u.damage(n), u.heal(n), u.locate(location) What a unit can be told. damage and heal also take { percent }.
on.created, on.died, on.killed, on.morphed, on.order A function run each time something happens to a unit. Events
stats(unitType), stats(weapon), stats(upgrade), stats(tech), stats(player) The game's tables. The game's tables
memory.game.frame, memory.map.width, memory.vision.countdown Other values of the game.
keyPressed(p, key), keyHeld(p, key), clicked(p, button), on.key(key, fn) Keys and mouse buttons. Keys
mouse(p), underMouse(p, filter?), centerLocation(location, x, y), bounds(location) The cursor's place on the map; the unit nearest it, or null; a location moved onto a point; where a location is now.
chatted(p, pattern), on.chat(pattern, fn) null, or the values read out of a typed line. Chat
local.player, local.camera, local.mouse, local.selected, local.card, local.screen, await sync(p, value) What only this computer knows, and sending it to every computer. Local values
displayText(`… ${n} …`), name(p), color(p) A text with numbers, a player's name and colour in it, for the current player. Text
print(text, { to?, position? }) The same for others, in the "chat" area or on the "center" line.
<line>, <bar>, <cell>, ui.lines(p, () => …) Lines of JSX, in a .tsx file. Lines of JSX
playWav(sound, 0), tone(), noise(), pluck() Sounds, including clips the script makes. Sounds
import … from "trigscript/<name>" The standard library. Libraries

Keys for keyPressed are letters, digits, "F1" and "F7" … "F12", "Space", "Enter", "Escape", the arrows and the rest of the list the editor offers. The game keeps F2 to F6 to itself. Buttons are "left", "right" and "middle".

TrigScript beside TypeScript#

Outside program() the script is all of TypeScript: it runs when it is applied, with the whole language and its standard library. Inside a program, nearly all of the language works as in TypeScript, and what differs is set out in one table at TrigScript beside TypeScript. Everything a program cannot do is refused with a message as you type, never passed over in silence; What a program does not have says what to write instead.

The compiler and the commands TrigScript offers other plugins are described in the plugin's own README at scm-js/plugin-trigscript.

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.