Writing / Kalix, part 2 of 8

Kalix Drops Its Scripting Language: Agents Write the Game Code, People Tune It

In November I wrote that agents write the code now, and what I write is what a designer gets to touch. That piece was about a fighting game in Unreal. The same idea then went back into my own engine, and it took out a part of Kalix I had built on purpose: its scripting language.

Why the engine had one

Kalix embedded Luau, a small, fast scripting language that grew out of Lua. Scripts attached to things in a scene, reacted to events, and sent commands through the same queue as everything else (see part 1). By November, scripts could reach 124 engine functions, the engine’s own code editor understood them well enough to suggest completions and flag mistakes, and nearly every small game I had built on the engine was written in it.

The reason for all of that is old and sensible. Rebuilding an engine is slow. A scripting language lets the person making the game change how it plays without waiting for a compile, and without being an engine programmer.

Why that reason went away

Neither half of that reason survives agents writing the code.

The person writing gameplay code is no longer someone who needs a gentler language. It is an agent, and an agent writes Rust as easily as Luau. Worse, the scripting layer is a second language with its own rules, its own list of what it can and cannot reach, and its own gaps. Real defects in this engine lived in exactly those gaps. The documentation promised scripts a function for removing things from the world that had never been written, and five of my game projects built workarounds for it. A script could pass a rotation for a particle effect, and the engine silently threw it away.

And the slowness that scripting avoided only matters for the things a person changes over and over. Those are not the code. They are the numbers: how much damage, how far, how fast, how long. So the split I described in the earlier article applies here too:

  • The code decides how things work. Agents write it.
  • Data files say what the content is. Every number someone might tune lives there, with a plain default.
  • A person tunes those files in the editor, while the game runs, without a rebuild.

Taking it out in three steps

On November 26 I decided Luau goes. Deleting it at once would have removed the only way the editor could run gameplay before its replacement had been used even once, so it goes in three steps:

  1. Freeze. No new script functions. The count stays at 124.
  2. Make it optional. Luau became one build setting, on by default for now. Turned off, the scripting system compiles to an empty stand-in and the language is not in the program at all.
  3. Delete it, after a game has shipped a playable build without it.

What replaced it

A game is now a Rust module the engine calls every frame. The module can read the whole world and send commands, and nothing else: it gets no special access, the same as the agent and the editor.

The editor became a library. A game builds its own copy of the editor with its code linked in, so pressing Play in the editor runs the game’s real Rust code, not an imitation of it. The cost, measured: about 50 seconds to rebuild after a change to the game’s code, the same as rebuilding the game alone.

Fifty seconds is fine for code. It is far too slow for tuning. So the numbers live in data files, one file per kind of thing, and the engine never reads a single field of them. It hands the text to the game, and the game decides what it means. In the editor, a changed file is picked up while the game is running.

Two views of the editor's inspector. Left: a game data file called rules. Some rows have plain labels and units, such as Extra step surcharge, 1 stamina, and Throw range, 6.0 m; others show raw field names such as standoff_m 0.50 and spill_radius_m 0.60. Right: a file called ui with five settings, each with a unit: Beat 0.50 s, Glide speed 6.0 m/s, Story lines 6 lines, Text size 18 px, Dropped height 0.40 m.
The editor's inspector open on two of a game's data files. Rows the game describes get a plain label and a unit (Throw range, 6.0 m); rows it has not described yet show their raw field names (spill_radius_m). The file on the right is fully described. Nobody wrote either panel by hand; they are built from the files themselves.

The rules a designer surface is held to

The earlier article ended with instructions I give agents. For this engine they became rules a piece of work can fail, written into the engine’s own instructions:

  • Code decides how things work, never what the content is.
  • Every number someone might tune lives in a data file with a default, and appears in the inspector without anyone writing a panel for it.
  • Units are the designer’s: frames, centimetres, degrees, percent.
  • Every tool says why. A refusal comes with the reason and the setting that changes it.
  • Warn, do not decide. A value outside its sensible range gets a warning, and it is saved exactly as typed.
  • Nothing automated overwrites a tuned value. An edit changes one value in the file’s text and leaves every comment and every other line alone.
  • Checks confirm the content is complete and works. They never compare a tuned number to its original value.
  • Tests use the real content, not a stand-in.
  • Design decisions come to me as options, with a recommendation first.

The inspector follows them. If I save a file the game cannot understand, the game keeps its last good values and the editor says why.

Adding a new way to act while the game runs

The clearest test came from the game in part 6, where players type what their hero does and a model turns it into actions from a fixed list. In November the list of actions moved out of the code and into a data file.

With the game running in the editor, a line saying “headbutt the brute” became an ordinary punch, because there was no headbutt. I then added a headbutt to the actions file, saved it, and played the next round. The same line became a headbutt, the game announced the new action on screen, and the brute, left shaken by it, missed his next swing. No rebuild.

The game running inside the editor. The story panel reads: The rules changed: round 2 on uses the new ones. New way to act: headbutt (anyone, 3 stamina): hit it, then leave it shaken. Below it: ash: headbutt brute.
Round two, after the actions file was saved mid-game. The story says the rules changed and names the new action, and the next plan uses it.

What is not solved

  • Lists and maps cannot be edited in the inspector. The game’s effects, materials, reactions and actions are lists, so they are still edited as text, with exact syntax.
  • Only the editor watches files. A packed game reads its data once, when it starts.
  • When no action fits, the model quietly picks the nearest one. The headbutt line became a punch, and nothing drew the player’s eye to that.
  • The only designer so far is me. I know these surfaces work for the person who described them. I do not yet know that they work for anyone else.