scmJS docs

TrigScript language

What a program can say: numbers, arrays, maps, functions, classes, errors, tasks, units, events, input, text, sounds and libraries, and where it differs from TypeScript.

This is the language of a TrigScript program: what the code inside program(() => { … }) can say, and what it does in the game. Start with the TrigScript guide if you have not written a script yet. It has the quick start, trigger(), the workspace and testing. Come here when a program needs something the guide only mentions, or when you know TypeScript and want to know where a program is different.

A script has two halves. Outside program(), the script is TypeScript: it runs when the script is applied, with all of the language and its standard library, and what it records is ordinary triggers. Inside program(), every line has to become something the game can do while the map is played. Most of TypeScript comes through unchanged. These pages say what each part does, and what to write instead of the few parts that are not there.

Page What is on it
TrigScript beside TypeScript The whole comparison in one table
The script and the program What is worked out when the script is applied, and what runs in the game
Variables and numbers Numbers, booleans, records, undefined; u8, u16, u32; fractions and Math
Arrays Fixed and growing arrays; arrays of records, units, texts and arrays; the methods; patterns and spread
Tables, maps and sets Lists the script made, tables keyed by an id of the game, Map and Set
Control flow Loops within the frame, unrolled loops, labels, switch
Functions Inlined and called functions, functions that call themselves, game(), functions as values and closures
Classes Fields, methods, extends, and how an instance is kept
Errors try, catch, finally, throw and classes of error
Waiting and tasks sleep, async and await, tasks, Promise.all and race, generators, edges
Owners and per-player programs One program for every player, and shared()
Reading the game Every condition's quantity as a number; facts about the players
Units Loops over units, picks, a unit's fields and what it can be told
Events on.created, on.died, on.killed, on.morphed, on.order
The game's tables and memory stats() for costs, weapons, upgrades and colours; memory
Keys, the mouse and chat Presses, clicks, the cursor, typed lines; local and sync()
Text Texts with values, string variables and their methods, lines of JSX
Sounds and imported files Clips made when the script is built; videos, pictures, sounds and MIDI the script imports
Libraries The standard library's nine modules, and libraries other plugins provide
What a program does not have What is refused, and what to write instead

Every example on these pages compiles as it is written. A line that ends with a comment such as // 80 prints that when the example runs. Examples that name locations assume the map has them: Beacon, Spawn, Base, Pen, Gate, Exit and Cursor.