Skip to main content

Code forms

A build target's code form (code_mode in build_targets, Code form in Studio's Build Settings) decides how your BT scripts are shipped inside the game. It does not change what your game can do or which assets ship. The comparison table and quick advice are on the overview.

Studio namecode_modeStatus
Source · compile at startupsourceSupported (desktop and web)
Bytecode · precompiledbytecodeSupported (desktop and web)
Embedded AOT · single executableaot_embeddedSupported (Windows x64, Linux x64)
Shared AOT · adjacent DLL/SOaot_sharedSupported (Windows x64, Linux x64)
Linked AOT · native toolchainaot_linkedSupported (Windows x64, Linux x64)

If a target has no code_mode, the game's bt settings in game.json are used as written. aot_static is an old name for aot_linked and still works.

Source​

Your .bt files are packed into the executable and compiled each time the game starts. Startup takes longer as your game grows. On desktop the compiled code is turned into machine code while the game runs (the JIT); set "jit": "disabled" in bt to use the slower interpreter only. Players can find your script source, because it is packed into the executable and unpacked to a temporary folder at startup.

Use it for test builds and when you want to debug a shipped build.

Bytecode​

Your scripts are compiled when you build, into one precompiled program packed into the executable. No source ships. On desktop the JIT turns it into machine code at run time, as with Source.

Use it for releases, especially on the web. Bytecode makes your code hard to read but is not encryption.

Embedded AOT​

Your scripts are compiled to machine code when you build, and the machine code is packed into the executable. Startup does no compiling. No extra tools are needed.

At startup the game copies that machine code into memory and marks it as executable. Some locked-down systems forbid programs from doing that. If yours must run on one, use Shared AOT or Linked AOT.

Shared AOT​

Your scripts are compiled to a machine-code library that ships next to the executable:

MyGame/
MyGame.exe
bin/program.dll (bin/program.so on Linux)

No extra tools are needed. Ship the whole folder: if bin/program.dll is missing or renamed, the game does not start.

Linked AOT​

Your scripts are compiled to machine code and built into the game executable by a normal C compiler and linker. You get one ordinary executable with the fastest startup, and the game creates no executable memory while running.

Needs CMake and a C compiler that match your copy of cTurtle; see What you need installed. If the compiler or link fails, the build stops with an error; there is no fallback to another form.

Rules for all AOT forms​

  • Windows x64 and Linux x64 only. AOT forms are not available for web builds.
  • No BT debugging. You cannot step through BT code in an AOT build, and Studio's Debug Play refuses AOT builds.
  • Rebuild after every script change. There is no live code reload in an AOT build.
  • Same cTurtle version. The game is compiled and run with the same build of cTurtle. If you update cTurtle, rebuild the game.

Your own C code​

If your game has its own C code (Adding C code), it is compiled into the executable whatever code form you choose. Every desktop build of such a game needs the C toolchain. The code form still decides what ships: Shared AOT still adds bin/program.dll, the others stay a single executable.

Debugging a shipped build​

Shipped builds normally cannot be debugged. To make a debuggable desktop build:

  1. Use the source or bytecode code form.
  2. Set "bt_debug_runtime": true on the build target. No C compiler is needed for this; only a game with its own C code needs the C toolchain, as it does for any build.
  3. Turn on bt.debug in game.json with a port and token.

Then attach a debugger as described in bt-dap. Don't ship debug builds to players.

Errors​

MessageWhat to do
unknown code deployment modeFix the spelling of code_mode.
WebAssembly supports loose scripts and bytecode; BT AOT emits x64 codeUse source or bytecode for web targets.
loose-script mode requires source inputs in the projectA source target needs bt.sources in game.json, not a prebuilt program.