Keywords

BattleScript keywords are reserved words with special meaning in the language. They cannot be used as identifiers (variable, function or parameter names). They are grouped below by purpose.

Data types

intA signed integer, e.g. int score = 100;
uintAn unsigned (non-negative) integer.
floatA single-precision floating-point number.
doubleA double-precision floating-point number.
boolA boolean value: true or false.
stringA sequence of characters, e.g. string name = "Alice";
objectA collection of key/value pairs, e.g. { name: "Alice", score: 100 }.
arrayAn array of values. Prefer typed arrays such as int[] or string[].
anyA value of any type; used when the type can vary.
voidIndicates a function returns no value.
nullThe intentional absence of a value.
undefinedAn uninitialised value.

Variables and functions

constDeclares a constant that cannot be reassigned, e.g. const int MAX = 100;
returnExits a function, optionally returning a value.
pureMarks a function as having no side effects, enabling optimisations.
nativeMarks a function as implemented by the runtime or device firmware (declaration only, no body).

Control flow

ifRuns a block when a condition is true.
elseProvides the alternative branch for an if statement.
forA counted loop: for (int i = 0; i < n; i++) { }. (There is no while loop.)
breakExits the current loop.
continueSkips to the next iteration of the current loop.
evaluatePattern matching over a value; contains case and fallback branches.
caseA branch inside evaluate; can match one or more values: case (2, 3) => { }.
fallbackThe default branch inside evaluate when no case matches.
catchHandles errors raised in scope.
asAliases a caught error or an imported/exported name: catch a, b as err { }.

Event model

See States, Modules and Events for the full model.

stateA device mode; contains module blocks.
moduleA source of events within a state; contains event handlers.
eventAn event handler within a module, e.g. event EventEnum.DOWN (EventData evt) => { }.

Timers

See the Timers page for details.

afterRuns a block once after a delay in milliseconds: after 1000 { }.
everyRuns a block repeatedly at an interval: every 1000 { }.
limitCaps how many times an every timer runs: every 1000 limit 5 { }.
keepRetains an every timer across state changes: every 1000 keep { }.
cancelCancels a timer entirely.
stopPauses a timer.
startStarts (or restarts) a timer.
resumeResumes a stopped timer.

Types, enums and interfaces

enumDeclares a set of named constants. See Enums.
interfaceDescribes the shape of an object. See Interfaces.
extendsInherits members from another interface.

Program, configuration and modules

programDeclares program metadata (type, name, author, version).
exposeDeclares external configuration values that can be set before the program runs.
groupGroups related configuration properties inside an expose block.
importBrings names from another module into scope, e.g. import { log } from "./lib.bst";
includeTextually includes another .bst file: include "./battlecore/player.bst";
exportMakes declarations available to other modules.
fromSpecifies the source module in an import or re-export.
namespaceImports a whole library as a namespace: import namespace "./lib.bst";

Protocols

Used inside protocol blocks. See the Protocols page for full details.

protocolDeclares a bit-level encode/decode protocol: protocol "name" for "ir" { }.
defineDeclares a payload field of a sized type: define uint<4> "playerId";
requireAsserts a condition on a field during decoding.
terminateFlag on require that rejects the signal if the assertion fails.
stepA processing phase, optionally step decode or step encode.
decodeQualifies a step/parity block as applying to decoding.
encodeQualifies a step/parity block as applying to encoding.
parityA parity / validation block.
ruleA conditional rule; supports the ?: operator (only valid here).
xorBoolean XOR over a bits<N> or bytes<N> read.
xnorBoolean XNOR over a bits<N> or bytes<N> read.
bitsA read of N bits: bits<19>.
bytesA read of N bytes: bytes<2>.
offsetMoves the bit cursor to an absolute position.
forwardMoves the bit cursor forward by n.
rewindMoves the bit cursor back by n.
endMarks the end of a protocol phase.

Debugging

debuggerPauses execution at this point when running under a debugger.

Reserved (not currently used)

These words are reserved by the lexer but are not part of any current grammar rule. Avoid using them as identifiers.

functionReserved. Functions are written as "returnType name (params) => { }", without this keyword.
declareReserved for declaring external functions/variables.
externalReserved for marking external libraries.
switchReserved. Use evaluate for branching.
defaultReserved.
useReserved.

Related Topics