scmJS docs

TrigScript beside TypeScript

The table is about the inside of a program. Same means it is written and behaves as in TypeScript. Where it differs, the table says how. Anything that is missing is refused with a message as you type, never passed over in silence.

TypeScript In a program What is different
Types: annotations, interface, type, unions of literals, tuples, generics, as, !, satisfies Same Erased, as in TypeScript. Some also decide things: u8, u16 and u32 are widths, fixed is a number with a fraction, and Map<UnitType, V> is kept differently from Map<number, V>.
let, const, var Same A variable needs a first value (let n = 0). A const whose value the script already knows is worked out when the script is applied and costs the map nothing.
number Different A whole number of 32 bits, signed, that wraps at its ends as x | 0 does. It holds a fraction once one is stored into it. No NaN, Infinity or bigint. / of whole numbers is whole division, and dividing by 0 gives 0.
boolean Same Assigned with = only: no ||= or &&=.
string Mostly length, s[i] and slice count characters, where JavaScript counts UTF-16 units; they differ only past U+FFFF. A made text holds 1 023 bytes. replace and split take a text, not a regular expression.
null, undefined Mostly A unit or an instance may be none (if (u), u?.kill()). A number or a boolean may be undefined where TypeScript says so, as what find gives when nothing fits, and ??, !== undefined and ! read it.
Operators Same == and === are one thing, since nothing is converted. A shift by 32 or more leaves nothing. ** wants a power known when the script is built. Missing: delete.
if, while, do, for, for…of, switch, break, continue, labels Same A loop runs all its rounds within one frame, so one that never ends must sleep() on every path. A for over bounds the script knows is written out round by round. No for…in.
Functions: parameters, defaults, optional and rest parameters, recursion, generics Same The compiler writes a function out where it is used or calls it; the meaning is the same. One that calls itself cannot wait, and has a depth limit.
Arrow functions, closures, functions as values Mostly A function can be kept in a variable, an array, a field or a Map, and returned. An async function or a generator is not kept as a value.
Object literals Records A variable per field: nested, passed by reference, spread, taken apart by patterns. No methods or getters on a literal; a class has them.
Destructuring and spread Same f(...xs) wants a length the script knows, as TypeScript itself does.
Arrays Mostly Fixed or growing, of numbers, booleans, texts, units, records, instances, functions and arrays, with nearly all their methods. Missing: flat, and map into texts or records. An index past the end reads 0. const b = a copies the array.
Classes: fields, constructors, methods, get / set, static, private / #x, readonly, extends, super, abstract, implements, instanceof, type parameters Same Declared in the program or at the top of any file. No static blocks.
Map, Set Mostly Keys are numbers, units, ids of the game, or a few texts the script knows. Values are numbers, booleans or instances.
enum, const enum, namespace Same Their members are constants known when the script is built.
try / catch / finally / throw Mostly throw takes an Error or a class that extends one. An error nothing catches is shown in the game in red, and the program stops.
async / await, promises, generators Mostly await of sleep(), until(), an async call, a task, Promise.all, race and any; function* and for await. A race's losers stop where they are. No setTimeout: the timers library has after and every.
Modules Same import between the script's files, from "trigscript", from the standard library and from other plugins' libraries, and of videos, pictures, sounds and MIDI the script imported. Nothing from npm.
The standard library Some Most of Math, String(n), parseInt, Array.from. print() for console.log, random(n) for Math.random(). No JSON, Date or RegExp.
— Added What TypeScript has no word for: sleep, rose and once; reads of the game; units and loops over them; events; stats() and memory; keys, the mouse and chat; per-player programs.