iamar
World creators · API reference

World API 0.11

Every import a world script may call and every callback it may export: 107 imports, 25 callbacks. TypeScript forms follow the TypeScript adapter: out_* parameters become the return value, and a failed call returns null or a negative error code. Handles and player ids are plain numbers; strings are UTF-8. Generated from world_api.json — do not edit this page by hand; regenerate it (see the footer).

core

api_version since 0.1

Import · group: core

iamar.api_version(): number

wasm iamar.api_version() -> i32

(major << 16) | minor of the browser's API: 11 for 0.11.

log since 0.1

Import · group: core

iamar.log(text: string): void

wasm iamar.log(i32, i32) -> void

A line in the world's log (the author's console). <= 512 bytes, 50/s.

rand since 0.1

Import · group: core

iamar.rand(): number

wasm iamar.rand() -> f32

Uniform in [0, 1). Seeded per world, so every visitor's copy draws the same sequence.

time since 0.1

Import · group: core

iamar.time(): number

wasm iamar.time() -> f64

Seconds since the script started (game time; pauses with the game).

entity

entity_spawn since 0.1

Import · group: entity

iamar.entity_spawn(kind: EntityKind, x: number, y: number, z: number, yaw: number): EntityHandle

wasm iamar.entity_spawn(i32, i32, f32, f32, f32, f32) -> i32

A new entity; returns its handle (> 0). Kinds: chicken, box, sphere, marker, cylinder, capsule, cone, plane, light, spot, particles, label, tree (iamar city's countryside tree: 68 triangles, foot at the point, 3.6 m crown and 7.5 m tall, sized with entity_set_scale, the city's colours: entity_set_color refuses it; browser after CG-58p, job 12282), mesh:<id> (from mesh_create), or asset:<path>.glb from the world's own package. <= 256 entities (manifest budget up to 1024).

A negative return is an error code (IAMAR_E_*).

entity_remove since 0.1

Import · group: entity

iamar.entity_remove(h: EntityHandle): Status

wasm iamar.entity_remove(i32) -> i32

Remove one of this script's entities.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

entity_set_pos since 0.1

Import · group: entity

iamar.entity_set_pos(h: EntityHandle, x: number, y: number, z: number, yaw: number): Status

wasm iamar.entity_set_pos(i32, f32, f32, f32, f32) -> i32

Jump there; stops any move_to.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

entity_move_to since 0.1

Import · group: entity

iamar.entity_move_to(h: EntityHandle, x: number, y: number, z: number, speed: number): Status

wasm iamar.entity_move_to(i32, f32, f32, f32, f32) -> i32

Walk there in a straight line at speed m/s (<= 50), turning to face the way it goes.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

entity_pos since 0.1

Import · group: entity

iamar.entity_pos(h: EntityHandle): Position | null

wasm iamar.entity_pos(i32, i32) -> i32

Writes x, y, z, yaw.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

entity_play_anim since 0.1

Import · group: entity

iamar.entity_play_anim(h: EntityHandle, name: string): Status

wasm iamar.entity_play_anim(i32, i32, i32) -> i32

chicken: idle, walk, run, peck, flap; glTF assets: any animation in the file.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

entity_set_tint since 0.1

Import · group: entity

iamar.entity_set_tint(h: EntityHandle, r: number, g: number, b: number, a: number): Status

wasm iamar.entity_set_tint(i32, f32, f32, f32, f32) -> i32

Wash the entity in a colour (0-1); a = 0 removes it.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

entity_set_grounded since 0.1

Import · group: entity

iamar.entity_set_grounded(h: EntityHandle, on: boolean): Status

wasm iamar.entity_set_grounded(i32, i32) -> i32

A grounded entity stays on the terrain while it moves.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

entity_set_scale since 0.2

Import · group: entity

iamar.entity_set_scale(h: EntityHandle, sx: number, sy: number, sz: number): Status

wasm iamar.entity_set_scale(i32, f32, f32, f32) -> i32

Each axis clamped to 0.01-100.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

entity_set_visible since 0.2

Import · group: entity

iamar.entity_set_visible(h: EntityHandle, on: boolean): Status

wasm iamar.entity_set_visible(i32, i32) -> i32

Show or hide.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

entity_set_rot since 0.2

Import · group: entity

iamar.entity_set_rot(h: EntityHandle, pitch: number, yaw: number, roll: number): Status

wasm iamar.entity_set_rot(i32, f32, f32, f32) -> i32

Radians; pitch about +X, yaw about +Y, roll about +Z.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

entity_stop_anim since 0.2

Import · group: entity

iamar.entity_stop_anim(h: EntityHandle): Status

wasm iamar.entity_stop_anim(i32) -> i32

Stop the current animation.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

entity_set_health since 0.9

Import · group: entity

iamar.entity_set_health(entity: EntityHandle, hp: number, max: number): Status

wasm iamar.entity_set_health(i32, f32, f32) -> i32

Gives entity `entity` script-owned health: hp of max (hp is clamped to 0..max), and shows the browser's health bar over it. Call again to set it (healing, a new phase); max 0 takes the health and the bar away. 0 < max <= 1 000 000 (limit max_health). This is the world's own model: it never touches the browser's monsters, gold or XP. In a world with host rules, the host decides kills and its state delta drives this call on every copy. -1 unknown entity, -2 NaN/infinite hp, or max out of range. -3 while the setting iamar/game_api/client_08 is off.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

entity_damage since 0.9

Import · group: entity

iamar.entity_damage(entity: EntityHandle, amount: number): number

wasm iamar.entity_damage(i32, f32) -> i32

Takes amount from the entity's health (a negative amount heals, up to its max). 1 when this hit took it to 0: on_entity_killed(entity) follows; 0 otherwise, also for an entity already at 0 (it is never killed twice; entity_set_health brings it back). The entity stays until the script removes it. -1 unknown entity, -2 NaN/infinite amount, -4 the entity has no health. -3 while the setting iamar/game_api/client_08 is off.

A negative return is an error code (IAMAR_E_*).

entity_health since 0.9

Import · group: entity

iamar.entity_health(entity: EntityHandle): number

wasm iamar.entity_health(i32) -> f32

The entity's current health; -1.0 for an unknown entity, one without health, or while the game API setting (iamar/game_api/client_08) is off.

entity_path_to since 0.9

Import · group: entity

iamar.entity_path_to(entity: EntityHandle, x: number, y: number, z: number, speed: number): Status

wasm iamar.entity_path_to(i32, f32, f32, f32, f32) -> i32

Walks entity `entity` to (x, y, z) at speed m/s (capped at 8) round walls and props on the physics floor, with the townsfolk's collision-checked routing (steps, slopes and drops as theirs; no navmesh). on_path_done(entity, ok) follows when the walk ends. entity_set_pos, entity_move_to or a new entity_path_to on the same entity replaces it (ok 0); removing the entity ends it with no callback. Route searches share the browser's 1 ms a tick with the townsfolk; one script's walks share 1.5 ms a tick. 0 accepted; -1 unknown entity; -2 NaN/infinite, speed <= 0 or a target more than 128 m away (flat); -3 a dynamic (physics) entity or max_paths walks already running. -3 also while the setting iamar/game_api/client_08 is off.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

render

entity_set_color since 0.3

Import · group: render

iamar.entity_set_color(h: EntityHandle, r: number, g: number, b: number, a: number): Status

wasm iamar.entity_set_color(i32, f32, f32, f32, f32) -> i32

Base colour of a primitive or label, or the colour of a light / particles. a < 1 makes primitives see-through. Components clamped to 0-1.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

entity_set_material since 0.3

Import · group: render

iamar.entity_set_material(h: EntityHandle, metallic: number, roughness: number, emission: number, unshaded: number): Status

wasm iamar.entity_set_material(i32, f32, f32, f32, f32) -> i32

Surface of a primitive or mesh entity: metallic 0-1, roughness 0-1, emission energy 0-16 (glows in its own colour), unshaded >= 0.5 ignores lighting.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

entity_set_light since 0.3

Import · group: render

iamar.entity_set_light(h: EntityHandle, energy: number, range: number, angle: number): Status

wasm iamar.entity_set_light(i32, f32, f32, f32) -> i32

For light and spot entities: energy 0-16, range 0.1-60 m, spot cone angle 1-89 degrees (ignored for light). Colour comes from entity_set_color. No shadows. The cap is on lights *this script* spawned: `entity_spawn` of a `light` or `spot` returns `E_LIMIT` (-3) once the script holds 16 (manifest `limits.max_lights` may lower it); scene.json lights are not counted, and nothing is logged, so check the returned handle.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

entity_set_particles since 0.3

Import · group: render

iamar.entity_set_particles(h: EntityHandle, preset: ParticlePreset, rate: number): Status

wasm iamar.entity_set_particles(i32, i32, i32, f32) -> i32

For particles entities: preset smoke, fire, sparks, dust, magic, rain, snow, bubbles; rate 0-200 particles/s (0 stops it). <= 8 emitters per script (the cap counts only particle entities this script spawned; `entity_spawn` of `particles` returns `E_LIMIT` (-3) past it).

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

entity_set_text since 0.3

Import · group: render

iamar.entity_set_text(h: EntityHandle, text: string, size: number): Status

wasm iamar.entity_set_text(i32, i32, i32, f32) -> i32

For label entities: text floating in the world, always facing the camera. <= 128 bytes; size 0.05-4 m per line.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

mesh_create since 0.3

Import · group: render

iamar.mesh_create(vertices: Float32Array | readonly number[], indices: Uint32Array | readonly number[]): number

wasm iamar.mesh_create(i32, i32, i32, i32) -> i32

A custom triangle mesh; returns a mesh id (> 0) to spawn as kind mesh:<id>. vertices: vertex_count x 8 f32 (x, y, z, nx, ny, nz, u, v); indices: index_count u32 (triangles, so a multiple of 3). <= 4096 vertices and 12288 indices per mesh (bigger models belong in a .glb asset), 64 meshes, 1,000,000 vertices and 3,000,000 indices per world, 4 calls per second.

A negative return is an error code (IAMAR_E_*).

world

ground_y since 0.1

Import · group: world

iamar.ground_y(x: number, z: number): number

wasm iamar.ground_y(f32, f32) -> f32

Terrain height at (x, z).

travel_offer since 0.11

Import · group: world

iamar.travel_offer(address: string, text: string): Status

wasm iamar.travel_offer(i32, i32, i32, i32) -> i32

Offers the local visitor a trip to another world: a confirm dialog shows `text` (<= 200 bytes, UTF-8, shown as plain text, may be empty) and the destination address. Only if the visitor answers yes does the browser go, by the same path as walking into a portal (portal_entered(address)); no or no answer does nothing. Never automatic. `address` must be a world address as a portal accepts it (e.g. iamar://<name>/<world>, <= 130 bytes; not a bare #spawn) or -2. -3 more than one offer in 10 seconds (or one already waiting), or while the setting iamar/game_api/client_08 is off; -4 where there is no host to show the dialog. Returns 0 once the dialog is shown; the answer is not reported back to the script.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

door_set_open since 0.11

Import · group: world

iamar.door_set_open(id: string, open: number): Status

wasm iamar.door_set_open(i32, i32, i32) -> i32

Opens (open 1) or closes (open 0) the door of scene object `id` (a scene.json objects[] entry with a `door`, WORLD_FORMAT 4.4) for the local visitor only: open state is each visitor's own, so call it in every visitor's copy of the script to open it for everyone. The leaf moves over the door's `seconds`; a closing leaf pushes a visitor aside. Works for trigger "script" (a quest or puzzle door) and "interact". Returns 0, also when already as asked. -2 an id that is no object id or open not 0 or 1; -4 no door with that id; -3 an "approach" door, more than door_calls_per_sec calls a second, or the game API setting (iamar/game_api/client_08) is off.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

door_is_open since 0.11

Import · group: world

iamar.door_is_open(id: string): number

wasm iamar.door_is_open(i32, i32) -> i32

1 while the door of scene object `id` in this world is open or opening for the local visitor, 0 closed or closing (an approach door reads as the visitors' distance last set it). -2 an id that is no object id; -4 no door with that id. -3 also while iamar/game_api/client_08 is off.

A negative return is an error code (IAMAR_E_*).

quest_accept since 0.8

Import · group: world

iamar.quest_accept(quest_id: string): number

wasm iamar.quest_accept(i32, i32) -> i32

Take on one of this world's own quests (its id in the scene's quests, or "<this world's address>#<id>"), the same as accepting it from its giver: banner, tracker, markers and save. 1 accepted; 0 not now (already taken or done, its requires not done, no pouch room, saving paused); -2 a bad id or another world's quest (never allowed); -4 no such quest. Local and unverified: the visitor's browser decides, so a quest whose reward matters needs the host layer. -3 while the browser's game API 0.8 setting (iamar/game_api/client_08) is off, or past 4 quest calls a second.

A negative return is an error code (IAMAR_E_*).

quest_advance since 0.8

Import · group: world

iamar.quest_advance(quest_id: string, step: number): number

wasm iamar.quest_advance(i32, i32, i32) -> i32

Finish every objective of step `step` (0-based) of one of this world's own active quests, as if the player had done them; the next step begins, or after the last the quest is ready to hand in to its turn_in NPC. 1 advanced; 0 the quest is not active on that step (stale call); -2 a bad id, another world's quest, or a step with pickup/loot objectives (their items carry them); -4 no such quest. Rewards are still paid only by the hand-in. -3 while the browser's game API 0.8 setting (iamar/game_api/client_08) is off, or past 4 quest calls a second.

A negative return is an error code (IAMAR_E_*).

item_give since 0.11

Import · group: world

iamar.item_give(id: string, n: number): number

wasm iamar.item_give(i32, i32, i32) -> i32

Gives the visitor n of this world's item `id` (one of manifest.items), saved with their progress under this world's own key (never another world's items, never a slot of the city pouch). Returns the count now held (> 0); 0 when that would pass the item's stack (nothing given). -2 a bad id (1..64 of a-z 0-9 _ . -) or n outside 1..max_item_stack; -4 not an item of this world's manifest.items (another world's items never answer); -3 while the browser's items setting (iamar/game_api/items) is off, while the world's World Host is reachable (there the host rules own items), when the visitor's progress cannot be saved now, or past item_changes_per_sec (shared by item_give and item_take).

A negative return is an error code (IAMAR_E_*).

item_take since 0.11

Import · group: world

iamar.item_take(id: string, n: number): number

wasm iamar.item_take(i32, i32, i32) -> i32

Takes n of this world's item `id` from the visitor: 1 taken; 0 the visitor holds fewer than n (nothing taken). Errors as item_give.

A negative return is an error code (IAMAR_E_*).

item_count since 0.11

Import · group: world

iamar.item_count(id: string): number

wasm iamar.item_count(i32, i32) -> i32

How many of this world's item `id` the visitor holds (0 none). -2 a bad id; -4 not an item of this world's manifest.items; -3 while the items setting (iamar/game_api/items) is off or the world's World Host is reachable.

A negative return is an error code (IAMAR_E_*).

physics

raycast since 0.2

Import · group: physics

iamar.raycast(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number): RaycastHit | null

wasm iamar.raycast(f32, f32, f32, f32, f32, f32, i32) -> i32

Read-only ray query (<= 10 km): writes hit x, y, z and normal x, y, z; returns the hit entity's handle, 0 for world geometry, -4 on a miss.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

entity_set_collider since 0.3

Import · group: physics

iamar.entity_set_collider(h: EntityHandle, shape: number, sx: number, sy: number, sz: number): Status

wasm iamar.entity_set_collider(i32, i32, f32, f32, f32) -> i32

Give an entity a solid shape players bump into and raycasts hit: shape 0 none, 1 box (sx, sy, sz = full size), 2 sphere (sx = radius), 3 capsule (sx = radius, sy = height). Sizes 0.01-100.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

entity_set_physics since 0.3

Import · group: physics

iamar.entity_set_physics(h: EntityHandle, mode: number, mass: number): Status

wasm iamar.entity_set_physics(i32, i32, f32) -> i32

mode 0 scripted (the default: only the script moves it), 1 dynamic (falls, bounces and is pushed; needs a collider), 2 static. mass 0.01-10000 kg. <= 128 dynamic bodies per world.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

entity_apply_impulse since 0.3

Import · group: physics

iamar.entity_apply_impulse(h: EntityHandle, x: number, y: number, z: number): Status

wasm iamar.entity_apply_impulse(i32, f32, f32, f32) -> i32

Push a dynamic entity (N*s). Its velocity afterwards is capped at 200 m/s however many impulses a callback gives, and a dynamic entity never moves faster than 200 m/s.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

entity_set_velocity since 0.3

Import · group: physics

iamar.entity_set_velocity(h: EntityHandle, x: number, y: number, z: number): Status

wasm iamar.entity_set_velocity(i32, f32, f32, f32) -> i32

Set a dynamic entity's velocity (m/s, each component clamped to +/-200).

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

entity_velocity since 0.3

Import · group: physics

iamar.entity_velocity(h: EntityHandle): Vector3 | null

wasm iamar.entity_velocity(i32, i32) -> i32

Writes the entity's velocity x, y, z (0 for scripted entities that are not moving).

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

entity_set_trigger since 0.3

Import · group: physics

iamar.entity_set_trigger(h: EntityHandle, radius: number): Status

wasm iamar.entity_set_trigger(i32, f32) -> i32

Make the entity a trigger zone of this radius (0.1-50 m; 0 turns it off): on_trigger_enter / on_trigger_exit fire as players come and go.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

audio

sound_play since 0.2

Import · group: audio

iamar.sound_play(name: SoundName, x: number, y: number, z: number): Status

wasm iamar.sound_play(i32, i32, f32, f32, f32) -> i32

A sound at a point: cluck, squawk, bell, click, door, jump, land, select, gear, or asset:<path>.ogg from the world's package (<= 2 MiB each, 32 files). 10/s. For music and longer ambience use audio_play.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

audio_play since 0.5

Import · group: audio

iamar.audio_play(name: string, flags: number, volume: number, fade: number): number

wasm iamar.audio_play(i32, i32, i32, f32, f32) -> i32

Play asset:<path>.ogg from the world's package (Ogg Vorbis, <= 32 MiB each, 16 files, 64 MiB in all), or stream an https:// Ogg Vorbis URL (port 443, a host the manifest lists in `stream_hosts`, else -2; no redirects; fetched after the visitor's first gesture; <= 16 MiB and 20 min each, 4 URLs and 32 MiB per script; the visitor sees every host and can turn streams off in Settings > Privacy). flags: 1 loop, 2 music (the world's one music track; a new one fades the old out), 4 positional (see audio_place). volume 0-1, fade = fade-in s (0-30). Returns a track handle (> 0), -2 bad name or flags, -3 with 8 live tracks or past 4 calls/s, -4 missing or refused file (a failed stream just ends: audio_state 0). Silent until the visitor's first click or key (audio_state 3). World mute and music volume win; tracks stop when the visitor leaves. sound_play for short effects.

A negative return is an error code (IAMAR_E_*).

audio_stop since 0.5

Import · group: audio

iamar.audio_stop(track: number, fade: number): Status

wasm iamar.audio_stop(i32, f32) -> i32

Stop a track, fading out over fade seconds (0-30; 0 at once). 0 also for a track that already ended; -1 for a handle audio_play never returned.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

audio_pause since 0.5

Import · group: audio

iamar.audio_pause(track: number, paused: boolean): Status

wasm iamar.audio_pause(i32, i32) -> i32

Pause (1) or resume (0) a track where it was. -4 when it already ended.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

audio_volume since 0.5

Import · group: audio

iamar.audio_volume(track: number, volume: number, fade: number): Status

wasm iamar.audio_volume(i32, f32, f32) -> i32

Change a track's volume (0-1) over fade seconds (0-30). -4 when it already ended.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

audio_state since 0.5

Import · group: audio

iamar.audio_state(track: number): number

wasm iamar.audio_state(i32) -> i32

0 ended or stopped, 1 playing, 2 paused, 3 waiting (for the visitor's first click or key press, or for its file to decode); -1 for a handle audio_play never returned.

A negative return is an error code (IAMAR_E_*).

audio_place since 0.5

Import · group: audio

iamar.audio_place(track: number, entity: number, x: number, y: number, z: number): Status

wasm iamar.audio_place(i32, i32, f32, f32, f32) -> i32

Where a positional track (flag 4) sounds from: entity 0 = the fixed point (x, y, z); else it follows that entity of this script, (x, y, z) from its origin, and ends when the entity is removed. Heard fully within ~8 m, silent beyond 80 m. -2 for a track without flag 4, -1 for an unknown entity, -4 when the track already ended.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

speech_say since 0.6

Import · group: audio

iamar.speech_say(entity: number, text: string, voice: string, speed: number): number

wasm iamar.speech_say(i32, i32, i32, i32, i32, f32) -> i32

Say text (<= 8192 chars) from entity, or with entity 0 as a caption along the bottom; the caption shows at once. A voice is added only when the visitor has the local voice runtime, has clicked or pressed a key in the world, has NPC speech on, and the world is within 12 voiced lines and 4000 voiced characters a minute; else it is a caption for its reading time. voice: empty for the default `af_heart` (unknown voices fall back to it); ASCII, <= 64 bytes. speed 0.5-2 (0 = 1). One line at a time per world: a new line from the same entity replaces its old one, another entity's waits its turn (at most 4 waiting). Heard within 30 m of the entity; world mute and NPC speech volume win; the visitor's own NPC conversation goes first; all stops when the visitor leaves or the script stops. Returns a handle (> 0), -1 unknown entity, -2 empty text, bad voice or NaN speed, -3 with 4 waiting or past 4 calls/s.

A negative return is an error code (IAMAR_E_*).

speech_stop since 0.6

Import · group: audio

iamar.speech_stop(line: number): Status

wasm iamar.speech_stop(i32) -> i32

Stop a line (its voice and caption) and start the next waiting one; 0 stops every line of this world. 0 also for a line that already finished; -1 for a handle speech_say never returned.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

speech_state since 0.6

Import · group: audio

iamar.speech_state(line: number): number

wasm iamar.speech_state(i32) -> i32

0 finished or stopped, 1 preparing (the voice is being made, or the line waits its turn), 2 speaking, 3 caption only (no voice runtime, a phone, before the visitor's first click or key, NPC speech muted, past the minute budget, or the voice failed). -1 for an unknown handle.

A negative return is an error code (IAMAR_E_*).

time

timer_after since 0.2

Import · group: time

iamar.timer_after(ms: number, tag: number): Status

wasm iamar.timer_after(i32, i32) -> i32

Calls on_timer(tag) after ms (0-86,400,000). <= 64 pending.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

timer_cancel since 0.2

Import · group: time

iamar.timer_cancel(tag: number): number

wasm iamar.timer_cancel(i32) -> i32

Cancels every pending timer with this tag; returns how many.

A negative return is an error code (IAMAR_E_*).

timer_repeat since 0.2

Import · group: time

iamar.timer_repeat(ms: number, tag: number): Status

wasm iamar.timer_repeat(i32, i32) -> i32

Calls on_timer(tag) every ms (1-86,400,000) until cancelled.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

players

players_count since 0.2

Import · group: players

iamar.players_count(): number

wasm iamar.players_count() -> i32

Players in the world now, including remote visitors.

A negative return is an error code (IAMAR_E_*).

player_id since 0.2

Import · group: players

iamar.player_id(index: number): number

wasm iamar.player_id(i32) -> i32

Id of the index-th player (0 <= index < count), ascending.

A negative return is an error code (IAMAR_E_*).

player_pos since 0.1

Import · group: players

iamar.player_pos(id: PlayerId): Position | null

wasm iamar.player_pos(i32, i32) -> i32

Writes x, y, z, yaw.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

player_set_pos since 0.2

Import · group: players

iamar.player_set_pos(id: PlayerId, x: number, y: number, z: number, yaw: number): Status

wasm iamar.player_set_pos(i32, f32, f32, f32, f32) -> i32

Teleport the local player (portals, respawns, checkpoints). A remote player's own copy of the script moves them; here it returns -1.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

player_is_local since 0.3

Import · group: players

iamar.player_is_local(id: PlayerId): number

wasm iamar.player_is_local(i32) -> i32

1 for a player at this computer (the keyboard's player, and from 0.10 every couch co-op slot 1002..1004), 0 for a remote visitor, -1 for an unknown id.

A negative return is an error code (IAMAR_E_*).

player_name since 0.3

Import · group: players

iamar.player_name(id: PlayerId): string | null

wasm iamar.player_name(i32, i32, i32) -> i32

Copies up to cap bytes of the player's display name (UTF-8); returns its full length.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

player_key since 0.3

Import · group: players

iamar.player_key(id: PlayerId): string | null

wasm iamar.player_key(i32, i32, i32) -> i32

A per-visit room key for the player, the same in every visitor's copy of the script during this visit (player ids are local to each copy). NOT stable across visits or reconnects, so do not use it as a persistent save key. ASCII, <= 64 bytes; returns its full length.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

player_seated since 0.11

Import · group: players

iamar.player_seated(id: PlayerId): number

wasm iamar.player_seated(i32) -> i32

1 while player `id` sits or lies on a seat (a scene object's `seat`, WORLD_FORMAT 4.4, or a city bench), 0 standing, -1 for an unknown id. A remote visitor reads 0: whether they sit is not sent to other copies. There is no sit event: check it in on_tick or a timer. -3 also while the setting iamar/game_api/client_08 is off.

A negative return is an error code (IAMAR_E_*).

player_seat since 0.11

Import · group: players

iamar.player_seat(id: PlayerId): string | null

wasm iamar.player_seat(i32, i32, i32) -> i32

Copies up to cap bytes of "<object id>#<seat index>" for the scene seat player `id` sits on (the scene.json objects[] id, or the builder's name for an object without one, and the index in its seat list, e.g. "bench#0"); returns its full length. -4 standing (or a remote visitor) or on a seat that is no scene object's (a city bench); -1 an unknown id. -3 also while the setting iamar/game_api/client_08 is off.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

player_stand since 0.11

Import · group: players

iamar.player_stand(id: PlayerId): number

wasm iamar.player_stand(i32) -> i32

Stands a local player up from a seat, as any move does (back where they walked up from). 1 stood up, 0 was not seated (nothing moves); -1 an unknown id or a remote player (their own copy of the script stands them), as player_set_pos. -3 also while the setting iamar/game_api/client_08 is off.

A negative return is an error code (IAMAR_E_*).

player_set_movement since 0.11

Import · group: players

iamar.player_set_movement(id: PlayerId, run_speed: number, jump_height: number, gravity: number, air_control: number, roll: number): Status

wasm iamar.player_set_movement(i32, f32, f32, f32, f32, i32) -> i32

Customized worlds only: a local player's movement in this world. run_speed m/s 1-14 (iamar: 7), jump_height m 0-4 (1.64), gravity m/s2 4-40 (19.29), air_control 0-2 (1), roll 1 on 0 off; < 0 keeps iamar's. Undone when the script stops. -1 unknown or remote id, -2 out of range, -3 past movement_calls_per_sec or setting off.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

local_player_max since 0.11

Import · group: players

iamar.local_player_max(max: number): Status

wasm iamar.local_player_max(i32) -> i32

Players at this computer the world takes, 1-4 (iamar 4; 1 = single player); more pads cannot join. Kept until the script stops. -2 outside 1-4.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

player_set_body since 0.11

Import · group: players

iamar.player_set_body(id: PlayerId, asset: string, clips: string): Status

wasm iamar.player_set_body(i32, i32, i32, i32, i32) -> i32

Customized worlds only: this copy shows player `id` as asset ("asset:x.glb", rigged, <= 12k triangles) with clips mapped to iamar states, "idle=Idle;walk=Walk" (idle required); "" restores iamar's. -1 unknown id, -2 bad map or model, -3 rate or setting off, -4 no file.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

player_damage since 0.9

Import · group: players

iamar.player_damage(amount: number): number

wasm iamar.player_damage(f32) -> i32

Hurts this visitor's own local player by amount (capped at 100, the hero's full health; limit max_player_damage) through the game's combat, so the hit flash, sound, pad rumble, knock-out and revive are the browser's own. 1 the hit knocked the player out, 0 hurt. It can never hurt another visitor: a visitor copy is not trusted, so a world sends a host command for that. -2 amount not > 0 or NaN, -4 no local player or no combat here, -3 while combat ignores hits (the player is already knocked out, or the creator preview holds the game), past 10 calls a second (player_damage_per_sec), or while the game API setting (iamar/game_api/client_08) is off.

A negative return is an error code (IAMAR_E_*).

player_slot since 0.10

Import · group: players

iamar.player_slot(id: PlayerId): number

wasm iamar.player_slot(i32) -> i32

The local slot of player `id` in couch co-op (several people on pads at one computer): 1 for the keyboard's player (id 1), 2..4 for the extra local players (ids 1002..1004, 1000 + slot, added with on_enter when they join and removed with on_leave), 0 for a remote visitor, -1 for an unknown id. Extra slots exist only when the browser's local-players setting is on. -3 also while the setting iamar/game_api/client_08 is off.

A negative return is an error code (IAMAR_E_*).

local_player_count since 0.10

Import · group: players

iamar.local_player_count(): number

wasm iamar.local_player_count() -> i32

How many players at this computer the script sees: 1 alone, up to 4 in couch co-op (ids 1 and 1002..1004). -3 also while the setting iamar/game_api/client_08 is off.

A negative return is an error code (IAMAR_E_*).

player_damage_slot since 0.10

Import · group: players

iamar.player_damage_slot(slot: number, amount: number): number

wasm iamar.player_damage_slot(i32, f32) -> i32

player_damage on local slot `slot` (1..4, see player_slot). Slot 1 is exactly player_damage; slots 2..4 hurt that slot's hero through the game's combat (its own health, knock-out and revive beside player 1). Same cap (max_player_damage) and the same 10 calls a second (player_damage_per_sec) shared with player_damage. 1 the hit knocked that player out, 0 hurt; -2 a slot outside 1..4 or amount not > 0 or NaN; -4 no such local player or no combat here; -3 past the rate or while that player is already knocked out. -3 also while the setting iamar/game_api/client_08 is off.

A negative return is an error code (IAMAR_E_*).

storage

kv_get since 0.1

Import · group: storage

iamar.kv_get(key: string): Uint8Array | null

wasm iamar.kv_get(i32, i32, i32, i32) -> i32

Copies up to cap bytes of the value; returns its full length, or -4.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

kv_set since 0.1

Import · group: storage

iamar.kv_set(key: string, value: Bytes): Status

wasm iamar.kv_set(i32, i32, i32, i32) -> i32

A value of 0 bytes deletes the key. Keys <= 128 bytes, values <= 4 KiB, 64 KiB per world. Stored on this visitor's machine.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

kv_keys since 0.8

Import · group: storage

iamar.kv_keys(prefix: string): string | null

wasm iamar.kv_keys(i32, i32, i32, i32) -> i32

Lists the kv keys that start with prefix (empty = all; <= 128 bytes), sorted, one per line ('\n'). Copies up to cap bytes; returns the full length of the list (0 = none). The browser's 'quest:' view is not listed, nor a key that contains a line break. -3 while the game API 0.8 setting is off.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

network

world_message since 0.1

Import · group: network

iamar.world_message(data: Bytes): Status

wasm iamar.world_message(i32, i32) -> i32

Send bytes (<= 1 KiB, 20/s) to every other visitor's copy of this script; they arrive in on_message_from (or on_message). Peer-to-peer over the room's encrypted links.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

message_to since 0.3

Import · group: network

iamar.message_to(id: PlayerId, data: Bytes): Status

wasm iamar.message_to(i32, i32, i32) -> i32

Send bytes to one remote player's copy of this script (same limits as world_message, sharing its rate).

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

is_authority since 0.3

Import · group: network

iamar.is_authority(): number

wasm iamar.is_authority() -> i32

1 if this copy is the world's authority, else 0: the copy whose visitor has the smallest player key among everyone in the room, so normally exactly one copy is. Use it to coordinate (who spawns, who keeps score), never as security: a hostile visitor can arrange to be the authority, so check what other copies send you.

A negative return is an error code (IAMAR_E_*).

host_available since 0.10

Import · group: network

iamar.host_available(): number

wasm iamar.host_available() -> i32

1 when this world has host rules (trusted rules on its World Host, GAME_API.md 5) and this visitor holds a current seat there, so host_command can reach them; 0 otherwise, and always 0 while the browser's host rules setting (iamar/game_api/host_layer) is off.

A negative return is an error code (IAMAR_E_*).

host_command since 0.10

Import · group: network

iamar.host_command(data: Bytes): number

wasm iamar.host_command(i32, i32) -> i32

Sends `data` (<= max_host_command bytes) to the world's host rules as this computer's first player: host_command_slot(1, data). The World Host knows the sender from the visitor's verified connection; the bytes carry no identity. Returns a request id > 0; on_host_result(req, status, reply) follows exactly once. -2 data longer than max_host_command or a bad pointer; -3 past host_commands_per_sec, or no host rules reachable (host_available() 0).

A negative return is an error code (IAMAR_E_*).

host_command_slot since 0.10

Import · group: network

iamar.host_command_slot(slot: number, data: Bytes): number

wasm iamar.host_command_slot(i32, i32, i32) -> i32

host_command as local slot `slot` (1..4, see player_slot): slots 2..4 are couch co-op players, each its own player in the host rules (its own records and board rows). Returns a request id > 0 answered by on_host_result. -2 a slot outside 1..4, data longer than max_host_command or a bad pointer; -4 no such local player here; -3 past host_commands_per_sec (shared with host_command) or no host rules reachable.

A negative return is an error code (IAMAR_E_*).

camera

camera_set since 0.3

Import · group: camera

iamar.camera_set(mode: number, x: number, y: number, z: number, tx: number, ty: number, tz: number): Status

wasm iamar.camera_set(i32, f32, f32, f32, f32, f32, f32) -> i32

mode 0 gives the camera back to the player; mode 1 looks from (x, y, z) at (tx, ty, tz) (cutscenes, puzzles). Esc, the browser's menus and leaving the world always give it back, and after Esc the script cannot take it again for 10 seconds (-3).

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

camera_set_split since 0.11

Import · group: camera

iamar.camera_set_split(mode: number): Status

wasm iamar.camera_set_split(i32) -> i32

Customized worlds: how players at this computer see it. 0 one shared view (iamar's), 1 a view each once 2 play (side by side; 3-4 in quarters), 2 shared until one is 16 m from the group. Each view redraws the scene. Kept until the script stops. -2 bad mode.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

camera_set_mode since 0.8

Import · group: camera

iamar.camera_set_mode(mode: number): Status

wasm iamar.camera_set_mode(i32) -> i32

Camera modes beside camera_set: 0 gives the view back to the player's own camera; 2 follows the entity named by the last camera_follow (-4 when there is none or it is gone); 3 looks down from above the local player (8 m + 2 x the camera_set_zoom distance, slightly tilted), keeping up as they move (-4 without a local player). Mode 1 is camera_set(1, ...) (-2 here). A followed entity that is removed gives the view back. Esc, the browser's menus and leaving the world give the view back in every mode, and after Esc no mode can take it for 10 seconds (-3). -3 while the browser's game API 0.8 setting (iamar/game_api/client_08) is off.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

camera_set_zoom since 0.8

Import · group: camera

iamar.camera_set_zoom(dist: number): Status

wasm iamar.camera_set_zoom(f32) -> i32

Sets the local player's camera distance (the mouse-wheel zoom) to dist metres, clamped to 0..15; below 0.7 the player sees in first person. Rooms may still pull the camera closer. In mode 3 it also sets the height. The player can zoom again afterwards. Allowed during the Esc block. -2 for NaN, -4 without a local player, -3 while iamar/game_api/client_08 is off.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

camera_follow since 0.8

Import · group: camera

iamar.camera_follow(entity: EntityHandle, dist: number, height: number): Status

wasm iamar.camera_follow(i32, f32, f32) -> i32

Takes the view (mode 2) and follows entity `entity` from dist m behind it (on its +Z side, so it turns with the entity) and height m above, looking at a point 1 m above it; the camera eases after it. dist and height 0..40, not both under 0.5 m together (-2). -1 for an unknown entity, -3 during the Esc block or while iamar/game_api/client_08 is off.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

input

input_bind since 0.3

Import · group: input

iamar.input_bind(key: number, on: boolean): Status

wasm iamar.input_bind(i32, i32) -> i32

Ask for on_input events for a key: Godot key codes for A-Z (65-90), 0-9 (48-57), Space (32) and the arrows (4194319-4194322). Esc, Enter, Tab and the F keys are the browser's and are refused. The key keeps its normal game meaning too. <= 32 keys.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

pad_bind since 0.8

Import · group: input

iamar.pad_bind(button: number, on: boolean): Status

wasm iamar.pad_bind(i32, i32) -> i32

Ask for on_pad events for a gamepad button: 0 A (south), 1 B (east), 2 X (west), 3 Y (north), 4 LB, 5 RB, 6 LT, 7 RT (triggers: pressed past 0.6, released under 0.4), 8 left stick click, 9 right stick click, 10-13 d-pad up/down/left/right. Start, Back and Guide are the browser's. The button keeps its normal game meaning too. <= 14 buttons. Until local players exist every pad is slot 1. -3 while the browser's game API 0.8 setting (iamar/game_api/client_08) is off.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

input_axis since 0.8

Import · group: input

iamar.input_axis(slot: number, axis: number): number

wasm iamar.input_axis(i32, i32) -> f32

Current value of an input axis of local player slot (1 until local players exist): 0 move x (right +), 1 move y (forward +), the left stick plus the movement keys, length <= 1; 2 look x (right +), 3 look y (up +), the right stick; 4 LT, 5 RT, 0..1. 0.0 for an unknown slot or axis, or while the game API 0.8 setting is off.

ui

Since 0.4 a script can also build whole pages (shops, journals, notice boards): ui_page_set takes a JSON page described by ui_page.schema.json, ui_page_show places it as an overlay, a modal or a surface on an entity, ui_page_patch changes one node, and the player's clicks and input arrive in on_ui_event. Set a page once, then only patch it.

ui_note since 0.1

Import · group: ui

iamar.ui_note(text: string): void

wasm iamar.ui_note(i32, i32) -> void

A short note on the player's screen, marked as the world's. <= 512 bytes, 4/s.

ui_text since 0.3

Import · group: ui

iamar.ui_text(id: number, text: string, x: number, y: number, size: number): Status

wasm iamar.ui_text(i32, i32, i32, f32, f32, f32) -> i32

Create or update text on the world's screen layer at (x, y) in 0-1 of the window, size 8-64 px. <= 256 bytes. The layer sits under the browser's own UI and is framed as the world's.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

ui_button since 0.3

Import · group: ui

iamar.ui_button(id: number, text: string, x: number, y: number, w: number, h: number): Status

wasm iamar.ui_button(i32, i32, i32, f32, f32, f32, f32) -> i32

Create or update a clickable button (position and size in 0-1 of the window); a click calls on_ui(id).

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

ui_bar since 0.3

Import · group: ui

iamar.ui_bar(id: number, value: number, x: number, y: number, w: number): Status

wasm iamar.ui_bar(i32, f32, f32, f32, f32) -> i32

Create or update a progress bar filled to value (0-1); its colour follows entity-style ui_color.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

ui_color since 0.3

Import · group: ui

iamar.ui_color(id: number, r: number, g: number, b: number, a: number): Status

wasm iamar.ui_color(i32, f32, f32, f32, f32) -> i32

Colour of a UI element's text or fill (0-1).

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

ui_remove since 0.3

Import · group: ui

iamar.ui_remove(id: number): Status

wasm iamar.ui_remove(i32) -> i32

Remove a UI element. Ids are the script's own (1-2,147,483,647); <= 32 elements.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

ui_page_set since 0.4

Import · group: ui

iamar.ui_page_set(page: number, json: UiPage | string): Status

wasm iamar.ui_page_set(i32, i32, i32) -> i32

Create or replace page 1-8 from a JSON page (api/ui_page.schema.json): a tree of nodes the browser builds into its own controls. <= 64 KiB, <= 512 nodes per page, <= 2000 nodes across the world's pages. The page stays hidden until ui_page_show. Invalid JSON or schema gives E_BAD_ARG with the error path in the world's log.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

ui_page_patch since 0.4

Import · group: ui

iamar.ui_page_patch(page: number, node: number, json: UiPatch | string): Status

wasm iamar.ui_page_patch(i32, i32, i32, i32) -> i32

Change one node's properties (text, value, style, visible, enabled, children...; $defs/patch in the schema) without rebuilding the page. <= 8 KiB, 60 patches/s per page.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

ui_page_show since 0.4

Import · group: ui

iamar.ui_page_show(page: number, mode: UiShowMode, entity: number): Status

wasm iamar.ui_page_show(i32, i32, i32) -> i32

mode 0 hidden, 1 overlay (a panel under the browser's own UI, framed as the world's), 2 modal (centred, takes mouse and keys; Esc always closes it; for 1.5 s after the player closes a modal no page may open as one, E_LIMIT), 3 surface drawn on entity (a box or plane of this script; the page fills its front face; <= 4 surfaces), 4 window (a floating window with chrome the browser draws: a title bar with the page's "window" title and the world's address, close, drag, resize grip and z-order; <= 4 windows; showing one again raises it). entity is 0 unless mode is 3.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

ui_page_surface since 0.4

Import · group: ui

iamar.ui_page_surface(page: number, px_w: number, px_h: number): Status

wasm iamar.ui_page_surface(i32, i32, i32) -> i32

Resolution of a page shown as a surface, 128-1024 pixels a side (default 512 x 512).

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

ui_page_remove since 0.4

Import · group: ui

iamar.ui_page_remove(page: number): Status

wasm iamar.ui_page_remove(i32) -> i32

Remove a page and its controls.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

ui_toast since 0.7

Import · group: ui

iamar.ui_toast(text: string, variant: string, msec: number): Status

wasm iamar.ui_toast(i32, i32, i32, i32, i32) -> i32

A short self-dismissing notice at the bottom of the player's screen, marked as the world's. variant: neutral, info, success, warning or danger (empty = neutral); msec 1000-15000 (0 = 4000). At most 3 shown and 8 queued (E_LIMIT beyond), 4/s. Never takes the mouse or keys.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

ui_dialog since 0.7

Import · group: ui

iamar.ui_dialog(page: number, title: string, text: string, buttons: string): Status

wasm iamar.ui_dialog(i32, i32, i32, i32, i32, i32, i32) -> i32

A modal dialog on page number `page`: title, message and 1-4 buttons (buttons is a JSON array of label strings). Button i (1-based) sends on_ui_event(page, i, 1) and closes the dialog; Esc closes it with on_ui_event(page, 0, 5). Modal rules of ui_page_show apply (one at a time, 1.5 s reopen cooldown). 2/s.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

ui_value since 0.4

Import · group: ui

iamar.ui_value(page: number, node: number): string | null

wasm iamar.ui_value(i32, i32, i32, i32) -> i32

Copy an input's current value as UTF-8 (input/textarea text, checkbox "0"/"1", slider as decimal text, select as the chosen index) into out, up to cap bytes; returns its full length. Node 0 of a page shown as a window: the window's "x,y,w,h" in UI units.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

ui_focus since 0.4

Import · group: ui

iamar.ui_focus(page: number, node: number): Status

wasm iamar.ui_focus(i32, i32) -> i32

Move keyboard focus to an input on an overlay or modal page (a surface page needs the player's click first). E_BAD_ARG while the browser has the keyboard (address bar, chat, a browser panel, the Esc menu).

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

chat

chat_post since 0.8

Import · group: chat

iamar.chat_post(text: string): Status

wasm iamar.chat_post(i32, i32) -> i32

Appends one line (<= 200 bytes, UTF-8) to the visitor's chat log, marked as the world's ('[world] ' prefix, markup shown as plain text). Local only: other players never see it. <= 2 a second. -2 for an empty line, -4 where there is no chat box, -3 while the browser's game API 0.8 setting (iamar/game_api/client_08) is off.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

npc

npc_spawn since 0.9

Import · group: npc

iamar.npc_spawn(kind: string, x: number, y: number, z: number, yaw: number): EntityHandle

wasm iamar.npc_spawn(i32, i32, f32, f32, f32, f32) -> i32

Spawns a talking NPC: an ordinary entity (same kinds, caps and entity_* calls as entity_spawn; its handle works with all of them) that npc_set_dialogue can give lines and choices. Until it has dialogue the interact key reaches it as on_interact. <= max_npcs NPCs (they count as entities too). Errors as entity_spawn (-2 bad kind name or position, -3 limit, -4 unknown kind); -3 while the setting iamar/game_api/client_08 is off.

A negative return is an error code (IAMAR_E_*).

npc_set_dialogue since 0.9

Import · group: npc

iamar.npc_set_dialogue(npc: EntityHandle, text: string, choices: string): Status

wasm iamar.npc_set_dialogue(i32, i32, i32, i32, i32) -> i32

What NPC `npc` says when the local player presses the interact key next to it: text = the speaker's name on the first line, then the line itself (text without a line break has no name); <= 1000 bytes, shown as plain text (markup is not applied). choices = up to 6 lines ('\n'-separated, empty lines skipped), <= 80 characters each; the browser adds Farewell. The browser's own dialogue panel opens (Esc or B closes it), and a picked choice closes it and sends on_npc_choice. Called from on_npc_choice for the NPC just answered, the panel opens again with the new dialogue, so a conversation can go on; otherwise a change shows the next time the player talks. Empty text and choices take the dialogue away. <= 10 a second. Local and unverified: a choice that decides an outcome needs the host layer. -1 not an NPC of this script, -2 too long, invalid UTF-8 or more than 6 choices; -3 while the setting iamar/game_api/client_08 is off.

Fails with a negative error code (IAMAR_E_*); out-values come back null on failure.

Callbacks — functions your world exports

Export the ones you need; the browser calls them. iamar_alloc is required with on_message / on_message_from.

on_init since 0.1

Callback (your world exports it)

function on_init(): void

wasm iamar.on_init() -> void

Once, after instantiation.

on_tick since 0.1

Callback (your world exports it)

function on_tick(dt: number): void

wasm iamar.on_tick(f32) -> void

About 10 times a second (tick_hz); dt is seconds since the last tick (<= 0.5).

on_enter since 0.1

Callback (your world exports it)

function on_enter(player: PlayerId): void

wasm iamar.on_enter(i32) -> void

A player arrives (after on_init for everyone already there). The local player is id 1; from 0.10 extra couch co-op players at this computer are ids 1002..1004 (player_slot) and arrive when they join.

on_leave since 0.1

Callback (your world exports it)

function on_leave(player: PlayerId): void

wasm iamar.on_leave(i32) -> void

A player leaves.

on_interact since 0.1

Callback (your world exports it)

function on_interact(player: PlayerId, entity: EntityHandle): void

wasm iamar.on_interact(i32, i32) -> void

A player uses an entity (the interact key within 2.5 m).

on_timer since 0.2

Callback (your world exports it)

function on_timer(tag: number): void

wasm iamar.on_timer(i32) -> void

A timer_after / timer_repeat fired.

on_message since 0.1

Callback (your world exports it)

function on_message(data: Uint8Array): void

wasm iamar.on_message(i32, i32) -> void

Bytes from another copy of the script (used when on_message_from is not exported).

on_message_from since 0.3

Callback (your world exports it)

function on_message_from(player: PlayerId, data: Uint8Array): void

wasm iamar.on_message_from(i32, i32, i32) -> void

Bytes from the copy of the script running for this player.

on_trigger_enter since 0.3

Callback (your world exports it)

function on_trigger_enter(player: PlayerId, entity: EntityHandle): void

wasm iamar.on_trigger_enter(i32, i32) -> void

A player walked into a trigger zone.

on_trigger_exit since 0.3

Callback (your world exports it)

function on_trigger_exit(player: PlayerId, entity: EntityHandle): void

wasm iamar.on_trigger_exit(i32, i32) -> void

A player left a trigger zone.

on_contact since 0.3

Callback (your world exports it)

function on_contact(a: EntityHandle, b: EntityHandle): void

wasm iamar.on_contact(i32, i32) -> void

Two of the script's dynamic entities, or a dynamic entity and the world (b = 0), started touching.

on_click since 0.3

Callback (your world exports it)

function on_click(player: PlayerId, entity: EntityHandle): void

wasm iamar.on_click(i32, i32) -> void

The local player clicked an entity with the mouse (needs a collider).

on_input since 0.3

Callback (your world exports it)

function on_input(key: number, pressed: boolean): void

wasm iamar.on_input(i32, i32) -> void

A key asked for with input_bind went down (1) or up (0).

on_ui since 0.3

Callback (your world exports it)

function on_ui(id: number): void

wasm iamar.on_ui(i32) -> void

A ui_button was clicked.

on_ui_event since 0.4

Callback (your world exports it)

function on_ui_event(page: number, node: number, kind: number): void

wasm iamar.on_ui_event(i32, i32, i32) -> void

Something happened on a page node: kind 1 click, 2 change (input, textarea, checkbox, slider, select; typing is coalesced to one per node per frame), 3 submit (Enter in an input), 4 link, 5 closed (the player closed a modal or window page), 7 opened (a window page; node 0), 8 moved (the player moved or resized a window page; node 0). Shares the per-frame allowance with timers and messages.

iamar_alloc since 0.1

Callback (your world exports it)

function iamar_alloc(len: number): number

wasm iamar.iamar_alloc(i32) -> i32

Required with on_message / on_message_from: returns a buffer of len bytes the host fills; the script owns it afterwards.

on_pad since 0.8

Callback (your world exports it)

function on_pad(slot: number, button: number, pressed: boolean): void

wasm iamar.on_pad(i32, i32, i32) -> void

A pad button asked for with pad_bind went down (1) or up (0) on the pad of local player slot.

on_quest_event since 0.8

Callback (your world exports it)

function on_quest_event(quest_id: Uint8Array, kind: number): void

wasm iamar.on_quest_event(i32, i32, i32) -> void

One of this world's own quests changed for this visitor, however it happened (an NPC, a pickup, a script call): kind 1 accepted, 2 a step done (the next began, or the last: ready to hand in), 3 completed (handed in), 4 abandoned (its progress was dropped). quest_id is the world's own id. Seen at most 4 times a second, so a quick run of changes may arrive as its last kind only; no events for the states found when the script starts (read those with kv_get "quest:<id>"). Needs iamar_alloc. Never sent while the game API 0.8 setting is off.

on_entity_killed since 0.9

Callback (your world exports it)

function on_entity_killed(entity: EntityHandle): void

wasm iamar.on_entity_killed(i32) -> void

entity_damage took entity `entity` to 0 health (once per death). The entity is still there unless the script removed it since; remove it, play a death, or give it health again. Never sent while the game API setting (iamar/game_api/client_08) is off.

on_npc_choice since 0.9

Callback (your world exports it)

function on_npc_choice(player: PlayerId, npc: EntityHandle, choice: number): void

wasm iamar.on_npc_choice(i32, i32, i32) -> void

The player picked choice `choice` (0-based, in the order npc_set_dialogue gave them) in NPC `npc`'s dialogue. Farewell, Esc and a pick from a dialogue that has changed since are not sent. Only the local player (1) talks to NPCs today. Never sent while the game API setting (iamar/game_api/client_08) is off.

on_path_done since 0.9

Callback (your world exports it)

function on_path_done(entity: EntityHandle, ok: number): void

wasm iamar.on_path_done(i32, i32) -> void

The walk entity_path_to started for `entity` ended: ok 1 it arrived (within 0.15 m), 0 it did not (no way found, out of time: 3x the straight-line time + 10 s, or replaced by entity_set_pos / entity_move_to / a new entity_path_to). Never sent while the game API setting (iamar/game_api/client_08) is off.

on_host_result since 0.10

Callback (your world exports it)

function on_host_result(req: number, status: number, reply: Uint8Array): void

wasm iamar.on_host_result(i32, i32, i32, i32) -> void

The answer to host_command / host_command_slot request `req`: status >= 0 is the host rules' own (0 ok, > 0 the world's refusal code) with their reply bytes (<= max_host_command); status < 0 the command did not run: -3 refused for rate or load, -4 no current seat or that slot is not registered on the World Host, -2 refused as malformed, -1 anything else (a rules error, a stopped runtime, an outcome still unknown after the browser's retries). A command whose answer was lost with the connection is sent again with the same operation id once the seat is back, so it runs at most once. Needs iamar_alloc.

on_host_message since 0.10

Callback (your world exports it)

function on_host_message(data: Uint8Array, slot: number): void

wasm iamar.on_host_message(i32, i32, i32) -> void

Bytes (<= max_host_command) the host rules sent this visitor (send_to / broadcast in iamar_host): `slot` 0 sent to everyone, 1..4 to that local player only. Needs iamar_alloc.

on_host_state since 0.10

Callback (your world exports it)

function on_host_state(key: Uint8Array, value: Uint8Array): void

wasm iamar.on_host_state(i32, i32, i32, i32) -> void

One record of the World Host's shared game state changed (GAME_API.md 5.3): `key` is the record id, `value` its new bytes, empty when it was erased. A fresh snapshot (first connect, after a gap in the pushes) arrives as one call per record, and records it no longer lists as erasures; a key changed again before delivery is delivered once with its newest value. Needs iamar_alloc: key and value come in ONE iamar_alloc(key_len + value_len) buffer, the value right after the key (value_ptr = key_ptr + key_len).

on_item_used since 0.11

Callback (your world exports it)

function on_item_used(item_id: Uint8Array): void

wasm iamar.on_item_used(i32, i32) -> void

The visitor pressed Use on a held item of this world in the Character & Gear panel. Nothing is taken (call item_take). At most 4 a second. Needs iamar_alloc. Not sent while the World Host is reachable.

Error codes

Calls that fail return a negative i32. In TypeScript an out-value comes back null instead.

CodeNameMeaning
-1IAMAR_E_BAD_HANDLEbad handle
-2IAMAR_E_BAD_ARGbad argument
-3IAMAR_E_LIMITlimit reached
-4IAMAR_E_NOT_FOUNDnot found

Limits

Hard limits added by each API version, from world_api.json; the full budget list lives in WORLD_FORMAT.md.

Added in 0.11

LimitValue
max item defs64
max item stack9,999
item changes per sec4
door calls per sec10
movement calls per sec4
body calls per sec8

Added in 0.10

LimitValue
max host command1,024
host commands per sec10

Added in 0.9

LimitValue
max health1,000,000
player damage per sec10
max player damage100
max npcs32
npc dialogue per sec10
max paths32

Added in 0.8

LimitValue
max bound pad buttons14
max chat post200
chat posts per sec2
camera max zoom15
camera follow max40

Added in 0.6

LimitValue
max speech text8,192
max speech queued4
speech lines per min12
speech chars per min4,000

Added in 0.5

LimitValue
max tracks8
max track files16
max track bytes33,554,432
track bytes total67,108,864
max streams4
max stream bytes16,777,216
stream bytes total33,554,432

Added in 0.4

LimitValue
max pages8
max page bytes65,536
max page nodes512
page nodes total2,000
max page depth32
max patch bytes8,192
patches per sec60
max surfaces4
surface px min128
surface px max1,024
surface click m15
surface freeze m40
max page images32
max image px2,048
image bytes total16,777,216
max list items1,000
max select options64

Added in 0.3

LimitValue
max lights16
max emitters8
max dynamic128
max meshes64
max mesh vertices4,096
mesh vertices total1,000,000
max ui32
max ui text256
max label text128
max bound keys32
max sounds32
max sound bytes2,097,152
max mesh indices12,288
mesh indices total3,000,000
meshes per sec4
max speed200
camera lockout s10