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