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
int | A signed integer, e.g. int score = 100; |
uint | An unsigned (non-negative) integer. |
float | A single-precision floating-point number. |
double | A double-precision floating-point number. |
bool | A boolean value: true or false. |
string | A sequence of characters, e.g. string name = "Alice"; |
object | A collection of key/value pairs, e.g. { name: "Alice", score: 100 }. |
array | An array of values. Prefer typed arrays such as int[] or string[]. |
any | A value of any type; used when the type can vary. |
void | Indicates a function returns no value. |
null | The intentional absence of a value. |
undefined | An uninitialised value. |
Variables and functions
const | Declares a constant that cannot be reassigned, e.g. const int MAX = 100; |
return | Exits a function, optionally returning a value. |
pure | Marks a function as having no side effects, enabling optimisations. |
native | Marks a function as implemented by the runtime or device firmware (declaration only, no body). |
Control flow
if | Runs a block when a condition is true. |
else | Provides the alternative branch for an if statement. |
for | A counted loop: for (int i = 0; i < n; i++) { }. (There is no while loop.) |
break | Exits the current loop. |
continue | Skips to the next iteration of the current loop. |
evaluate | Pattern matching over a value; contains case and fallback branches. |
case | A branch inside evaluate; can match one or more values: case (2, 3) => { }. |
fallback | The default branch inside evaluate when no case matches. |
catch | Handles errors raised in scope. |
as | Aliases a caught error or an imported/exported name: catch a, b as err { }. |
Event model
See States, Modules and Events for the full model.
state | A device mode; contains module blocks. |
module | A source of events within a state; contains event handlers. |
event | An event handler within a module, e.g. event EventEnum.DOWN (EventData evt) => { }. |
Timers
See the Timers page for details.
after | Runs a block once after a delay in milliseconds: after 1000 { }. |
every | Runs a block repeatedly at an interval: every 1000 { }. |
limit | Caps how many times an every timer runs: every 1000 limit 5 { }. |
keep | Retains an every timer across state changes: every 1000 keep { }. |
cancel | Cancels a timer entirely. |
stop | Pauses a timer. |
start | Starts (or restarts) a timer. |
resume | Resumes a stopped timer. |
Types, enums and interfaces
enum | Declares a set of named constants. See Enums. |
interface | Describes the shape of an object. See Interfaces. |
extends | Inherits members from another interface. |
Program, configuration and modules
program | Declares program metadata (type, name, author, version). |
expose | Declares external configuration values that can be set before the program runs. |
group | Groups related configuration properties inside an expose block. |
import | Brings names from another module into scope, e.g. import { log } from "./lib.bst"; |
include | Textually includes another .bst file: include "./battlecore/player.bst"; |
export | Makes declarations available to other modules. |
from | Specifies the source module in an import or re-export. |
namespace | Imports a whole library as a namespace: import namespace "./lib.bst"; |
Protocols
Used inside protocol blocks. See the Protocols page for full details.
protocol | Declares a bit-level encode/decode protocol: protocol "name" for "ir" { }. |
define | Declares a payload field of a sized type: define uint<4> "playerId"; |
require | Asserts a condition on a field during decoding. |
terminate | Flag on require that rejects the signal if the assertion fails. |
step | A processing phase, optionally step decode or step encode. |
decode | Qualifies a step/parity block as applying to decoding. |
encode | Qualifies a step/parity block as applying to encoding. |
parity | A parity / validation block. |
rule | A conditional rule; supports the ?: operator (only valid here). |
xor | Boolean XOR over a bits<N> or bytes<N> read. |
xnor | Boolean XNOR over a bits<N> or bytes<N> read. |
bits | A read of N bits: bits<19>. |
bytes | A read of N bytes: bytes<2>. |
offset | Moves the bit cursor to an absolute position. |
forward | Moves the bit cursor forward by n. |
rewind | Moves the bit cursor back by n. |
end | Marks the end of a protocol phase. |
Debugging
debugger | Pauses 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.
function | Reserved. Functions are written as "returnType name (params) => { }", without this keyword. |
declare | Reserved for declaring external functions/variables. |
external | Reserved for marking external libraries. |
switch | Reserved. Use evaluate for branching. |
default | Reserved. |
use | Reserved. |