Skip to content
Axiom/SDK
SDK / Handles and statuses

Handles and statuses

A mod never holds a pointer to anything in the game or the host. It holds handles: an entity, a panel, a list. And every call that can fail returns a status rather than trapping, so a mod decides what to do about it. This page is both.

What a handle is

A handle is two numbers, an index and a generation, and crosses as both:

Type
Names
Comes from
AxiomEntityQueryEntityId
An entity in the game
axiom_entity_query_alive
AxiomUiOverlayPanelId
A panel in the overlay
axiom_ui_overlay_panel
AxiomUiOverlayNodeId
A list or table in a panel
axiom_ui_overlay_list, axiom_ui_overlay_table

The host owns the table behind them. The index is checked against the table before anything is read, and nothing in a handle is ever treated as an address. The generation is drawn from the operating system's random generator for each slot, so a mod cannot guess one it was never given.

A handle lasts one frame

Handles are minted for the frame they were handed out in. Use them in that frame and ask again in the next; a handle kept into a later frame is stale, even when the same entity is still alive.

WRONGa handle kept across frames
/* Wrong: a handle kept from an earlier frame. */
static AxiomEntityQueryEntityId s_Held;

__attribute__((export_name("on_frame"))) void OnFrame(void) {
  AxiomVec3 at;
  if (axiom_entity_transform_position(s_Held.index, s_Held.generation, &at) !=
      0) {
    /* Status 1 every frame after the first: the handle is stale. */
  }
}
RIGHTthis frame's handles, this frame
/* Right: ask for this frame's handles, and use them this frame. */
__attribute__((export_name("on_frame"))) void OnFrame(void) {
  AxiomEntityQueryEntityId ids[64];
  const uint32_t alive = axiom_entity_query_alive(ids, 64);
  for (uint32_t at = 0; at < alive; ++at) {
    AxiomVec3 position;
    if (axiom_entity_transform_position(ids[at].index, ids[at].generation,
                                        &position) != 0) {
      continue;
    }
    /* ... */
  }
}

This is what makes a handle safe in a game that reuses slots. Cities: Skylines has sixteen thousand vehicle slots and no generations of its own, so a vehicle freed and another created in its slot look the same to the game. A handle from last frame stops resolving rather than reading the new vehicle.

The overlay works the same way today: a panel and its lists are opened each frame, and an id from an earlier frame names nothing.

Forged handles

A handle no correct mod could hold, such as an index past the end of the table, a generation of zero, or the wrong generation for a slot minted this frame, is a forgery. Each one a mod presents is counted. Past sixteen in a session, the host stops resolving anything that mod presents, real handles included, so a guess that eventually lands buys nothing. Other mods are unaffected. A handle kept too long is a bug rather than an attack, and is not counted.

Statuses

A call that can fail returns an int32_t status. 0 is success, and the result, if there is one, was written through the out pointer. Anything else means nothing was written. The numbers count the capability's declared errors from 1, in the order the IDL lists them.

Capability
1
2
entity.transform@1
StaleHandle: the handle is not this frame's, or the pack cannot read it
ReadOnly: set_position on a game or field that may not be written
camera@1
NoCamera: the pack has no camera, or could not read it
project@1
Offscreen: behind the camera, or no camera to project with
ui.overlay@1
The panel or node names nothing in this frame
The frame is full: too many panels, marks, cells or bytes
config@1
UnknownKey: the manifest declares no such key
WrongKind: the key is another kind, such as flag on a number

A pack answers every way a read can fail with 1 today, so a stale handle and a slot the pack could not read are the same status. A distinct status for each is planned.

Calls that return a count, such as axiom_entity_query_alive and axiom_entity_query_count, cannot fail: they return how many they wrote. A bool, such as axiom_entity_transform_writable, is 0 or 1.

Statuses are not faults

A status is the host saying no, and the mod carries on. A fault is the mod doing something no correct mod does, such as passing an out pointer outside its own memory, and it ends the callback and counts towards suspension (Frames and fuel). Check every status, and the host never needs to fault you.

Not built yet

  • TrackedEntityId, an identity that follows one entity across frames for the mod that needs it, is designed and not in the surface yet. A pack would have to declare it, because a game whose slot reuse is invisible cannot honestly offer it.