BT language reference
The exact rules of BT, the scripting language of cTurtle: what you can write, what it means, and the errors you get when something is wrong.
New to BT? Start with the language guide,
which explains the language with worked examples. Come here when you need a
precise answer. Library functions are in the
BT standard library (io, string, files, ...) and
the cTurtle API reference (cturtle/world, ...). The
compiler command line is ctbt.
| Page | Look here for |
|---|---|
| Lexical structure | Comments, doc comments, names, keywords, number, NaN/Infinity, string, interpolated string and character literals |
| Types | Built-in types, char, enums, arrays and maps, objects and interfaces, null, const, function types, conversions, equality |
| Declarations | Functions, trees, objects, interfaces, enums, constants and top-level variables, private (~) declarations, ECS queries, names and scopes |
| Statements | Loops and for ... in, if, switch, select, compound assignment, ++/--, the copy statement, guard blocks, reaching the end of a function |
| Expressions | Operators and precedence, calls, literals, string interpolation, indexing, type tests and downcasts, switch expressions, function values, branch/join/unless |
| Errors | error, fallible functions, ?, !!, throw, cleanup with &&, crashes (traps) |
| Concurrency | Tasks, channels, select, cancelling and timeouts, timers, Mutex, sharing data between tasks |
| Packages | Folders as packages, include and as, what a file can see, namespaces and qualified names, entry points such as main and gameMain |
| Execution | Number behaviour, memory, limits, determinism |
| Not in BT | Features BT leaves out, and what to write instead |
Terms used on these pages
- Compile error: the program is rejected before it runs. Error messages
are quoted in
code fontso you can search for them. - Fails: the operation raises an
errorthat your code can handle with!!or pass on with?(see Errors). - Trap: a crash of the current task, such as dividing an integer by zero or indexing past the end of an array. Traps cannot be caught; check before you divide or index.
- Task: a piece of work that runs concurrently with others, started with
branch(see Concurrency). - Host: the program that runs your scripts, for example a cTurtle game,
cTurtle Studio, or
ctbt run. The host decides which engine packages exist.