# Protocol: game, part 1 of 2

The `game` commands a program sends to a running game, as the engine describes them: what each takes, what it answers and what it does. Back to [all commands](../protocol-commands.md).

## game.info

`game.info {} -> {project: text, title: text, step: integer, checksum: text, scripts: [text], scenes: [text], scene: text, tuning: [record], poses: [record], actions: [text], players: integer, seed: integer, width: integer, height: integer, background: integer, filter: text, warnings: [text], stopped: record, failed_step: integer, whole: value, csharp: record, cooked: record}` · read, read-only

Describes the loaded game and where its simulation stands.

| Result | Type | Meaning |
| --- | --- | --- |
| `project` | text | The file the game was loaded from, as the engine was given it, with / between its parts. |
| `title` | text | What the game is called: the project's `title`, or null when it gives none. |
| `step` | integer | How many fixed steps have run. |
| `checksum` | text | The world's checksum at this step, 16 hex digits: what frost run prints as `world checksum`. Equal checksums mean equal worlds, on any machine. A project's `replay` holds another number, the checksum of a whole run (`run checksum`), which sums the world at every step. |
| `scripts` | [text] | The scripts' names: their paths as the project wrote them. |
| `scenes` | [text] | The scenes scene.load can start: the project's `scene`, then its `scenes`. |
| `scene` | text | The scene the game is in now, by its name in scenes. Empty for a bare scene file, which has no name. |
| `tuning` | [record] | One {name, value, default, min, max, step} per number of the project's [tuning] table, in name order: what a script reads as tuning.NAME now, what the project file says, and the least, the most and the spacing the project gives it, each null when it gives none. |
| `poses` | [record] | One {clip, seconds, loops, events: [{at, name}]} per clip of the project's [poses], in name order: what a model's clip of that name sends as a Pose plays it (each event's name and the moment of the clip it is sent at), with the clip's length and whether it goes round, as the project file says them (the length as the models the game loads have it: E0486 otherwise; whether it goes round the project's word, over the models'). [] for a project with none. Here beside tuning because it is the project's, not a model's: one entry serves every model with a clip of that name. |
| `actions` | [text] | The input actions input.set accepts. |
| `players` | integer | How many players have input. They count from 0. |
| `seed` | integer | The seed the random source started from at step 0. |
| `width` | integer | The frame's width in pixels; one world unit is one pixel. |
| `height` | integer | The frame's height in pixels. |
| `background` | integer | The colour behind everything, as 0xRRGGBB: the project's `background` under `[window]`. |
| `filter` | text | How pictures are sampled at another size: "nearest" or "linear", the project's `filter` under `[window]`. |
| `warnings` | [text] | What is probably a mistake though the game loaded, each line starting with a code. |
| `stopped` | record | null while the game can step. While a debugger holds a script stopped part way through a step: {file, line, reason}, where it stands and why, as debug.state says them. game.step, game.seek and scene.load are refused with E0441 until a debugger's client lets it go on (debug.continue); everything that reads is answered. |
| `failed_step` | integer | The step that failed when the last step did (a script's error, E0302 and the like): `step` is then that one, counted though it did not finish, and the step before it was the last good one. null when the last step finished, and after the game is put back to a moment (game.seek, game.restore, game.reset) that has none. |
| `whole` | value | true when the world is as a step left it whole; false when it is as the failed step left it part way, its later stages not run: game.seek {step: failed_step - 1} brings back the last good world where the game is on its recording. |
| `csharp` | record | null for a game with no C# script, and for an engine built without C#. For a game with one: {solution, dotnet, compiler}. solution is the path of the file a C# language server is started on for this game (game.slnx, in the engine's cache: the engine writes it and the project beside it whenever the game is loaded or checked, and an editor writes neither); dotnet is the major version of the .NET the engine runs scripts on, as text ("11"); compiler is the version of the engine's C# compiler ("5.12.0"), which a language server's own must not be older than. game.info adds scripts: each C# script's name with "ahead" when it runs compiled ahead of time (an exported game's, from its csharp/ folder) or "runtime" when the .NET runtime runs it, compiled as the game loaded. |
| `cooked` | record | What loading the game cooked, and drawing it (a model's pictures are cooked at the first frame), as {fresh, cached, ms, why}: fresh is how many models, pictures and atlases were cooked now, cached how many were taken from the cook's cache, ms how long the load and the draws that cooked took in milliseconds. why says why any were cooked now, one of "importers" (the engine's importer for them changed since a program last cooked in this cache, so each is cooked again once), "files" (the game's files are new or changed), "first" (the cache is new) or "off" (there is no cache: FROST_CACHE=off); null when none were. A reset or a reload does not change it. |

## game.check

`game.check {} -> {errors: integer, warnings: integer, problems: [record], csharp: record}` · read, read-only

Checks the game's files as they are now, without touching the running game: what loading them would refuse, and what it would warn of. The files are loaded into a second game that is thrown away, which runs what a load runs: each script's top level, and on_scene for the scene the game starts in. No step is run, no sound is played and no file is written. What only running the game finds (W1112, a joint that lost an end to a despawn) is in game.status, and frost run and frost test print it.

| Result | Type | Meaning |
| --- | --- | --- |
| `errors` | integer | How many problems would stop the game from loading. |
| `warnings` | integer | How many are probably mistakes though the game loads. |
| `problems` | [record] | Errors first: {severity, code, file, line, message}. severity is "error" or "warning"; file is the file's path from the project file's folder, with / between its parts on every system; file and line are null when the problem has none; message is what loading the game would say: it carries the code and what to do. A project file and a scene file are each read up to their first mistake. |
| `csharp` | record | null for a game with no C# script, and for an engine built without C#. For a game with one: {solution, dotnet, compiler}. solution is the path of the file a C# language server is started on for this game (game.slnx, in the engine's cache: the engine writes it and the project beside it whenever the game is loaded or checked, and an editor writes neither); dotnet is the major version of the .NET the engine runs scripts on, as text ("11"); compiler is the version of the engine's C# compiler ("5.12.0"), which a language server's own must not be older than. game.info adds scripts: each C# script's name with "ahead" when it runs compiled ahead of time (an exported game's, from its csharp/ folder) or "runtime" when the .NET runtime runs it, compiled as the game loaded. |

## game.step

`game.step {steps?: integer, until?: record} -> {step: integer, checksum: text, reached: value, stopped: record}` · write

Advances the simulation by fixed steps of 1/60 s, using the input held by input.set, not the project's recording: game.seek plays the recording to a step, as frost run and frost test do, so the same step of the two can show the game at different places. When a debugger stops a script it returns at once, with the steps so far and `stopped` saying where.

| Parameters | Type | Meaning |
| --- | --- | --- |
| `steps?` | integer | How many steps to run, from 1 to 36000. Left out: 1. |
| `until?` | record | A goal to stop at, looked at after each step: {scene: NAME} (the game is in that scene), {event: NAME} (the step sent that event), {field: "Component.field", op, value, entity} (an entity's field compares so; entity left out: any entity's) or {state: "key", op, value, script} (a key of a script's state compares so, with dots for keys inside tables; script left out: any script's). op is one of = != < <= > >= and may be left out for =. Left out: every step is run. |

| Result | Type | Meaning |
| --- | --- | --- |
| `step` | integer | How many fixed steps have run. |
| `checksum` | text | The world's checksum at this step, 16 hex digits: what frost run prints as `world checksum`. Equal checksums mean equal worlds, on any machine. A project's `replay` holds another number, the checksum of a whole run (`run checksum`), which sums the world at every step. |
| `reached` | value | true when the goal of until was met: the stepping stopped there, and step is the step that met it. false when the steps ran out first, or no goal was given. |
| `stopped` | record | null while the game can step. While a debugger holds a script stopped part way through a step: {file, line, reason}, where it stands and why, as debug.state says them. game.step, game.seek and scene.load are refused with E0441 until a debugger's client lets it go on (debug.continue); everything that reads is answered. |

## game.seek

`game.seek {step: integer} -> {step: integer, checksum: text, keyframes: record, from: integer, started: text, replayed: integer, ms: number}` · write

Puts the game at a step of the project's recording, as frost run --steps reaches it: for scrubbing a recorded game, and for showing a change before and after on the same input. A game only its recording has moved runs on from where it is; going back, or after game.step, world.set, scene.load, script.reload or a seeded reset, the game is put back to a moment of the recording the server kept on an earlier seek (one every 300 steps) and played on from there, or else loaded again from its files (a script changed with script.reload is then the file's again). It is loaded whenever that could make another game: a file of the game changed, or since the last load there was a script.reload, a tuning.set or blame.on, or a debugger is attached. Put back, the game's snapshots are kept, events.since starts at that moment and not at step 0 (from says where), and log.since has the lines printed before it.

| Parameters | Type | Meaning |
| --- | --- | --- |
| `step` | integer | The step to stand at, from 0 to 36000. Past the end of the recording every action is at rest. |

| Result | Type | Meaning |
| --- | --- | --- |
| `step` | integer | How many fixed steps have run. |
| `checksum` | text | The world's checksum at this step, 16 hex digits: what frost run prints as `world checksum`. Equal checksums mean equal worlds, on any machine. A project's `replay` holds another number, the checksum of a whole run (`run checksum`), which sums the world at every step. |
| `keyframes` | record | What the server keeps of the recording to go back by: {every, kept, steps, bytes, most_bytes}. A keyframe is taken every `every` steps (300) while a seek plays the recording; once they would take more than most_bytes (64 MiB) every other one goes and every doubles. kept is how many there are now, steps their steps in order (what a timeline marks as the places a seek starts from) and bytes about what they take: each is a snapshot of the game, game.snapshot's bytes. None are kept while one could be another game (see above). |
| `from` | integer | The step this seek played on from: where the game stood, a keyframe's step, or 0. |
| `started` | text | How it got to `from`: "here" (it ran on from where it stood), "keyframe" (put back to a keyframe) or "load" (the game loaded again from its files). |
| `replayed` | integer | How many steps it played from `from`: what the seek cost, with ms. |
| `ms` | number | How long the seek took, in milliseconds of the server's clock. Not part of the game: it differs from run to run. |

## game.time

`game.time {rate?: number} -> {step: integer, rate: number}` · write

Sets how fast the game runs by itself, where a clock runs it (frost dev, a browser tab): 1 is sixty steps a second, 0 is paused, 0.5 is half speed. game.step steps a paused game. Sound is never slowed or paused. Where time moves only by game.step (frost serve, frost mcp) the rate is kept and changes nothing.

| Parameters | Type | Meaning |
| --- | --- | --- |
| `rate?` | number | 0 to pause, or from 0.1 to 4. Left out: the rate stays as it is. |

| Result | Type | Meaning |
| --- | --- | --- |
| `step` | integer | How many fixed steps have run. |
| `rate` | number | The rate now. |

## game.reset

`game.reset {seed?: integer, width?: integer, height?: integer} -> {step: integer, checksum: text, seed: integer}` · write

Loads the game again from its files: step 0, the scene as written, every input at rest. Saves are kept: a game whose saves have a place (frost dev) starts from what is kept there, any other from the saves its recording declares. To empty a slot, save.set with no data.

| Parameters | Type | Meaning |
| --- | --- | --- |
| `seed?` | integer | Where the random source starts, from 0 to 4294967295. Left out: the project's seed. |
| `width?` | integer | With `height`: the frame's size from now on, in place of the project's, each from 1 to 4096. To see a game's interface at another shape. Left out: the size it has. |
| `height?` | integer | See `width`. |

| Result | Type | Meaning |
| --- | --- | --- |
| `step` | integer | How many fixed steps have run. |
| `checksum` | text | The world's checksum at this step, 16 hex digits: what frost run prints as `world checksum`. Equal checksums mean equal worlds, on any machine. A project's `replay` holds another number, the checksum of a whole run (`run checksum`), which sums the world at every step. |
| `seed` | integer | The seed the game now runs from. |

## game.snapshot

`game.snapshot {} -> {id: integer, bytes: integer, step: integer, checksum: text}` · write

Keeps the game as it stands, in the server's memory, to go back to with game.restore or to play from with game.try: for trying many inputs from one moment without playing the way there each time. It holds the world, the physics' own memory, the clock, the held input and the input so far, so a game put back goes on bit for bit as it did the first time. It does not hold what a script keeps in a `local` (keep what the game is in the world or in `state`), the scripts' code, or sound. The server keeps at most 4096 snapshots and 512 MiB of them (E0434 past either); game.reset, a game.seek that goes back and a changed project or scene file forget them all.

| Result | Type | Meaning |
| --- | --- | --- |
| `id` | integer | What game.restore, game.try and game.forget know the snapshot by. Ids count from 1 and are never given twice. |
| `bytes` | integer | About how many bytes the server uses to keep it. |
| `step` | integer | How many fixed steps have run. |
| `checksum` | text | The world's checksum at this step, 16 hex digits: what frost run prints as `world checksum`. Equal checksums mean equal worlds, on any machine. A project's `replay` holds another number, the checksum of a whole run (`run checksum`), which sums the world at every step. |

## game.restore

`game.restore {id: integer, again?: value} -> {step: integer, checksum: text, edits_after: [integer], code_changed: [text], changes: [record], again: integer}` · write

Puts the game back to a snapshot, which stays kept: the step, the world, the physics, the held input and the input so far are the snapshot's, and so are the game's saves (where the session keeps them in a place on disk, the place follows at the next step). What a client changed after the snapshot was taken is not made again by playing on with the same input (edits_after), and a script reloaded since then runs as it is now, never as it was (code_changed): a tool that scrubs takes a snapshot after each change it makes. With again, the changes are brought into the moment put back, as one: each command that made them is made again in it, in order, by the hand that sent it.

| Parameters | Type | Meaning |
| --- | --- | --- |
| `id` | integer | A snapshot's id, from game.snapshot. E0433 when none has it. |
| `again?` | value | true: makes the changes of edits_after again in the moment put back (a change no command made, like one a refused command left, is left out). An entity a change made is named by its new id in the changes after it. When one is refused now, the answer is its refusal and the game is as it was before the restore, to the bit. Left out: false. |

| Result | Type | Meaning |
| --- | --- | --- |
| `step` | integer | How many fixed steps have run. |
| `checksum` | text | The world's checksum at this step, 16 hex digits: what frost run prints as `world checksum`. Equal checksums mean equal worlds, on any machine. A project's `replay` holds another number, the checksum of a whole run (`run checksum`), which sums the world at every step. |
| `edits_after` | [integer] | The step count at each change a client made after the snapshot was taken that is not input: a write to the world (world.set, world.spawn, world.despawn and the like), scene.load, saves.set, debug.evaluate. Empty when stepping on with the same input goes where it went. |
| `code_changed` | [text] | The scripts whose code was swapped since the snapshot was taken (script.reload, a saved file): they go on as they are now. |
| `changes` | [record] | {step, what, hand, who, name}: each command that made the changes of edits_after, once, in order: the step it was made at, the command (null for a change no command is known to have made), the hand that sent it and its name (as session.hands gives them; 0 and null for a connection that said nothing) and what it changed, by the name the client gave (an entity, a scene, a slot). None writes a file, so none has a line: the line a client wrote is the client's. |
| `again` | integer | How many of changes were made again: 0 without again. |

## game.forget

`game.forget {id?: integer} -> {kept: integer, bytes: integer}` · write

Lets go of a snapshot, or of all of them, and says what is still kept.

| Parameters | Type | Meaning |
| --- | --- | --- |
| `id?` | integer | The snapshot to let go of. Left out: every snapshot. |

| Result | Type | Meaning |
| --- | --- | --- |
| `kept` | integer | How many snapshots are kept now. |
| `bytes` | integer | About how many bytes they take together. |
