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 name | code_mode | Status |
|---|---|---|
| Source · compile at startup | source | Supported (desktop and web) |
| Bytecode · precompiled | bytecode | Supported (desktop and web) |
| Embedded AOT · single executable | aot_embedded | Supported (Windows x64, Linux x64) |
| Shared AOT · adjacent DLL/SO | aot_shared | Supported (Windows x64, Linux x64) |
| Linked AOT · native toolchain | aot_linked | Supported (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:
- Use the
sourceorbytecodecode form. - Set
"bt_debug_runtime": trueon 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. - Turn on
bt.debugingame.jsonwith a port and token.
Then attach a debugger as described in bt-dap. Don't
ship debug builds to players.
Errors
| Message | What to do |
|---|---|
unknown code deployment mode | Fix the spelling of code_mode. |
WebAssembly supports loose scripts and bytecode; BT AOT emits x64 code | Use source or bytecode for web targets. |
loose-script mode requires source inputs in the project | A source target needs bt.sources in game.json, not a prebuilt program. |