Skip to main content

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.

PageLook here for
Lexical structureComments, doc comments, names, keywords, number, NaN/Infinity, string, interpolated string and character literals
TypesBuilt-in types, char, enums, arrays and maps, objects and interfaces, null, const, function types, conversions, equality
DeclarationsFunctions, trees, objects, interfaces, enums, constants and top-level variables, private (~) declarations, ECS queries, names and scopes
StatementsLoops and for ... in, if, switch, select, compound assignment, ++/--, the copy statement, guard blocks, reaching the end of a function
ExpressionsOperators and precedence, calls, literals, string interpolation, indexing, type tests and downcasts, switch expressions, function values, branch/join/unless
Errorserror, fallible functions, ?, !!, throw, cleanup with &&, crashes (traps)
ConcurrencyTasks, channels, select, cancelling and timeouts, timers, Mutex, sharing data between tasks
PackagesFolders as packages, include and as, what a file can see, namespaces and qualified names, entry points such as main and gameMain
ExecutionNumber behaviour, memory, limits, determinism
Not in BTFeatures 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 font so you can search for them.
  • Fails: the operation raises an error that 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.