Skip to main content

The BT Programming Language

This guide teaches BT, the language cTurtle game scripts are written in: its syntax, error handling, collections, concurrency and standard library. For exact rules, error messages and limits, see the BT language reference and the standard library reference.

BT is a statically typed, C-shaped language with automatic memory management and explicit concurrency. Code runs sequentially by default. branch starts concurrent work and join waits for its result. A fallible operation either propagates its error with ? or handles it with !!.

include "io";
include "time";

fn main() -> int {
println("Hello, World!");

task<void> pause = branch timer_after(0.1);
(join pause)?;

return 0;
}

Guide​

  1. Getting started — build and run a BT program.
  2. Language basics — types, variables, operators, enums, switch, loops, and control flow.
  3. Functions and modules — functions, function values, trees, constants and top-level variables, packages, includes, and namespaces.
  4. Error handling — error, throw, ?, !!, and deferred cleanup with &&.
  5. Objects and nullability — objects, interfaces, type tests and downcasts, private fields, const views, and nullable references.
  6. Strings — immutable strings, interpolation, characters, methods, and number formatting.
  7. Collections and buffers — arrays, growable slices, maps and map iteration, channels, and byte buffers.
  8. Concurrency — tasks, branch, join, select, timeouts with unless, and concurrent I/O.
  9. Standard library — math, process, stream, timer, mutex, file, directory, and TCP APIs.
  10. Component views — loop over every entity that has a set of components, reading and writing them as plain fields.
  11. Syntax reference — a compact source-language reference.

For cTurtle games and tools, JSON/YAML decoding loads text or registered assets directly into BT objects.

A useful mental model​

  • Every value has a static type.
  • Variables and object fields are mutable unless const or access rules forbid it.
  • Objects, interfaces, arrays, maps, channels, tasks, errors, and engine objects are references. Assignment creates another alias to the same value.
  • Rows from a component view are valid only during the system call. Keep them in locals and pass them to helpers; don't store them.
  • Memory is managed automatically. There is no manual allocation or freeing.
  • A call is sequential. branch starts concurrent work and returns a task<T>.
  • A fallible operation must be propagated, handled, or branched.
  • Library and application declarations live in packages. A file includes each package it uses, such as "io".
  • cTurtle adds its own packages, such as cturtle/world. The cTurtle API reference lists them.