Scripting: API reference
Everything the code of a block can do hangs from the game object. This is the complete list; if something is not here, the code cannot do it (that is what game.do is for: it reaches any block of the editor).
Before you start, read the plugin introduction and turn Scripting on in the Plugins section.
How things are named
In every function you can write the name of what you want (case does not matter) or its internal id: "Golden key", "basement door". Names are those of the language you are editing the project in. If a name does not exist, the code stops with a clear error, with its line, in the Play debugger; and before playing, Diagnostics already flags it (names are watched).
Two kinds of instructions
- Instant: reading or changing a value. No
awaitneeded. - Taking time (⏱): speaking, waiting, walking, changing scene… Put
awaitin front so the code waits for them to finish.
Variables
The project’s variables (Logic section) are read and written as properties of game.vars. The name is case-insensitive.
game.vars.coins = game.vars.coins + 5;
game.vars.coins += 5; // same as the line above
game.vars["Hero name"] = "Lola"; // names with spaces
if (game.vars.has_map) { /* … */ }| Instruction | What it does |
|---|---|
game.vars.name | The variable’s value: number, boolean or text, depending on its type. |
game.vars.name = value | Changes the variable (converted to its type: a number, true/false or text). |
game.get("name") · game.set("name", value) | The same as functions (useful when the name is in another JavaScript variable). |
Object.keys(game.vars) | Names of all variables. |
The variable must exist: create it first in Logic (or in the Variables panel). Writing to one that does not exist gives an error, so values are not lost to a misspelt name.
Inventory
| Instruction | What it does |
|---|---|
game.items.has("key") | true if the protagonist carries the item. |
game.items.count("coin") | How many units they carry (for stackable items). |
game.items.add("key", n = 1) | Gives the item (or n units). |
game.items.remove("key", n = 1) | Takes it away. |
game.items.list() | List with the names of what they carry. |
Where we are
| Instruction | What it returns |
|---|---|
game.scene | { id, name } of the current scene. |
game.player | { id, name, x, y }: the protagonist the player controls now and where they are. |
game.time | Seconds played. |
game.lang | The language the player plays in ("es", "en"…). It changes if the player changes it in the Options. |
game.visited("Basement") | true if the player has already been in that scene. |
game.objectiveStatus("Find the key") | "active", "done", "failed" or null if not started. |
These values are a snapshot taken when the block starts (and when each awaited instruction finishes): if another script changes them while yours waits, you will see it after the next await.
Your own data, saved
game.data is an object of yours, empty when a game starts. It is saved and loaded with the game: ideal for counters, lists or state that does not deserve a variable.
game.data.visits = (game.data.visits ?? 0) + 1;
game.data.secretStash = ["a", "b"];It only accepts plain data: numbers, text, booleans, lists and objects (no functions or circular references). It is shared by all the project’s code blocks.
Randomness and helpers
| Instruction | What it does |
|---|---|
game.random(a, b) | Random integer between a and b (both included). With one argument: from 0 to a. |
game.pick(list) | A random element of the list. |
game.log(...) · console.log(...) | Writes to the Play debugger Log (Code filter), with its line, and to the browser console (F12). At most 200 messages per block. |
You also have all standard JavaScript: Math, Array, Date, JSON, Map, regular expressions…
Saying and showing
| Instruction | What it does |
|---|---|
⏱ await game.say(who, "text") | A character says a line. who is "player" (the current protagonist) or a character name. The text accepts the usual tags: [var:gold], [calc:…], [duration:3]… |
⏱ await game.narrate("text") | Voice-over. |
⏱ await game.title("text", seconds = 3) | Full-screen title card. |
⏱ await game.wait(seconds) | Waits. |
⏱ await game.waitClick() | Waits for a player click. |
Characters
who is "player" or a character name. target is the name of a hotspot, scene object, character or entrance point in the current scene (or "hotspot:id", "prop:id", "character:id", "entrance:id").
| Instruction | What it does |
|---|---|
⏱ await game.walkTo(who, target, wait = true) | Walks to the target. With false it does not wait for arrival. |
game.teleport(who, target) | Places them instantly. |
game.face(who, "left" | "right" | "up" | "down") | Turns them. |
game.faceTarget(who, target) | Turns them towards something. |
⏱ await game.animate(who, "wave", loop = false) | Plays an animation. With true it repeats until another replaces it. |
game.follow(who, leader) | Makes who follow another character; game.follow(who, null) stops it. |
Scenes and objects
| Instruction | What it does |
|---|---|
⏱ await game.goto("Basement", "Stairs", "fade") | Changes scene. The entrance and the transition are optional. |
game.showProp("Lamp") · game.hideProp("Lamp") | Shows or hides a scene object. |
game.setPropState("Door", "open") | Changes its state. |
game.enableHotspot("Window", false) | Enables or disables a hotspot. |
game.objective("Find the key", "active" | "done" | "failed") | Changes a journal objective. |
⏱ await game.dialogue("Chat with the shopkeeper") | Starts a conversation and waits for it to end. |
⏱ await game.runScript("Open the safe") | Runs another script and waits. |
⏱ await game.endGame("The end") | Ends the game with that text. |
Sound, camera and interface
| Instruction | What it does |
|---|---|
game.sound("door.wav") | A sound effect (asset name). |
game.music("theme.mp3") · game.music(null) | Changes the music or stops it. |
game.loopSound("engine.ogg", untilStopped = true) | Loops a sound. With false, only while you stay in this scene. |
game.stopSound("engine.ogg", fade = 0.3) · game.stopSound(null) | Stops that sound (or every loop) with a fade of that many seconds. |
game.ambience("rain.ogg", fade = 1) · game.ambience(null) | Changes the ambience of the current scene (or silences it). |
game.sceneAmbience() | Goes back to the scene's own ambience. |
game.musicVolume(30, seconds = 1) | Raises or lowers the music (0 to 100) gradually. |
game.sceneSound("Waterfall", on = true) | Turns a sound placed in the scene on or off. |
game.soundFrom("knock.wav", "Door") | A sound that comes from something in the scene: it plays on its side and is quieter from afar. |
game.acoustics("cave" | "underwater" | "radio" | "custom name" | "scene", mix?) | Changes the acoustics (cave, underwater, radio or one of yours); "scene" goes back to the scene's. |
game.speechDuck("voice" | "always" | "never" | "project") | When the music goes down while someone speaks: only with recorded voice, always, never or as the project says. |
game.vibrate("light" | "medium" | "strong") | Vibrates the phone (Android, playing with a finger) unless the player turned it off. Does nothing on a computer or an iPhone. |
⏱ await game.cinematic("The ship arrives", wait = true) | Plays a cinematic (Cinematics plugin). |
⏱ await game.camera.pan(target, seconds?) | Moves the camera to something (without seconds, by distance). |
⏱ await game.camera.panBy(dx, dy, seconds?) | Shifts the camera some pixels. |
game.camera.snap(target) | Places the camera instantly. |
game.camera.follow(who) | The camera follows a character. |
game.camera.stopFollow() | The camera stops following whoever it followed. |
⏱ await game.camera.zoom(zoom, seconds?) | Zooms in (>1) or out (<1). |
⏱ await game.camera.reset(seconds?) | Follows the protagonist again, without zoom. |
⏱ await game.camera.shake(seconds, power?) | Shake. |
⏱ await game.camera.fade("in" | "out", seconds, color?) | Fade to black (out) or from black (in), or to another color. |
⏱ await game.light("#ffcc88", seconds) | Changes the scene lighting. "#ffffff" is normal. |
game.hud(visible = true, bars = false) | Shows or hides the interface and adds or removes the cinema bars. |
Multiplayer: game.net
With the Multiplayer plugin on, game.net gives access to the room: game.net.players, game.net.count, game.net.isHost, game.net.me, game.net.send("message") and game.net.announce("text"). Without a room, isHost is true and count is 1. See the reference.
Reaching any block: game.do, game.check and game.block
The editor’s blocks already do almost everything; these three functions put them within reach of the code.
game.do("sentence") ⏱
Runs one or several steps written exactly as in the human view (in Spanish or English). With several lines, conditions are written indented by 4 spaces, as in the editor.
await game.do("Set the variable Gold to 7");
await game.do(`If Gold > 5:
The player says: “I can afford it”.
Otherwise:
The player says: “I can't afford it”.`);If the sentence is not understood, the error says why. The available sentences are those of the block reference.
game.check("condition") ⏱
Evaluates a condition written as in the editor and returns true or false.
if (await game.check("If the player has Key")) { /* … */ }game.block(type, values) ⏱
Runs a block by its type (you see it in the block reference, Type field) with the values of its parameters (by id, not by name). For conditions it returns true or false.
await game.block("cam.shake", { seconds: 1 });
const ok = await game.block("cond.variable", { variable: "v_gold", op: ">", value: 5 });Errors and debugging
- A syntax error is flagged while you type (below the editor) and in Diagnostics.
- A runtime error (a name that does not exist, an exception…) interrupts the block and the game goes on. In an “If the code holds” block it counts as No. In Play it shows in Debugger → Log with its script and its line (“Code · “Script” · line 3: …”) and a Go to the block button; also in the browser console (F12) with the prefix
Código:. - A call without
awaitthat fails counts as an error too, even on the last line; and so does one that takes time (game.say…) withoutawait, if it fails before the code ends. - If the code does not respond for about five seconds (an infinite loop), it is stopped.
- With
console.log(…)orgame.log(…)you see values while testing: they show in the Log under the Code filter. More in Errors and console in Play.
Limits
- There is no network, no file access and no browser access (
window,document,localStorage,fetch… do not exist inside the code). - JavaScript local variables do not carry over from one block to another: use project variables or
game.data. - A block cannot wait for something forever without the engine noticing: use
game.waitinstead of your own timers. - The code runs when the script reaches the block; there are no events of its own: to react to something, use the editor’s normal events and call the code from there.
Complete list
Every instruction in one table. It comes from the same description as the editor's completion and the agent's guide, so it is always complete. To write the code in another editor, verb-game.d.ts has its types.
| Instruction | What it does |
|---|---|
game.vars | The project variables by name: game.vars.gold, game.vars["Name with spaces"]. Writing to one changes the variable (it must exist). |
game.get(name) | The value of a variable (same as game.vars[name]). |
game.set(name, value) | Changes a variable (converted to its type). |
game.items.has(item) | true if the protagonist carries the item. |
game.items.count(item) | How many units they carry. |
game.items.add(item, n = 1) | Gives the item (or n units). |
game.items.remove(item, n = 1) | Takes it away. |
game.items.setState(item, state) | Sets an inventory item to one of its states (by name: “half”). |
game.items.state(item) | The name of the state an inventory item is in (empty if it has no states). |
game.items.swap(item, newItem) | Swaps an item for another in the same inventory slot (if it is not carried, gives the new one). |
game.items.list() | The names of what they carry. |
game.scene | The current scene. |
game.player | The protagonist the player controls and where they are. |
game.time | Seconds played. |
game.lang | The language the player plays in ("es", "en"…). |
game.visited(scene) | true if the player has been in that scene. |
game.objectiveStatus(objective) | How a journal objective is going (null if not started). |
game.props.visible(prop) | true if the scene object is visible (looked up in the current scene first, then in all). |
game.props.state(prop) | The name of the state the scene object is in ("open", "closed"…). |
game.hotspots.enabled(hotspot) | true if the hotspot is enabled. |
game.regions.has(region, who = "player") | true if the character (by default the protagonist) is inside the region of the current scene, like the block "If in the region". In walkthroughs nobody is in any region. |
game.regions.enabled(region) | true if the region of the current scene is enabled. |
game.characters.where(who) | Which scene a character is in and where (in scene units; null if in none). |
game.countdown(variable) | The seconds left on that variable’s countdown (null if not running). |
game.timeOfDay | The time of day (time-of-day palettes), like the block "If it is…". |
game.containers.has(container, item) | true if the container (a chest, a shop…) holds that item. |
game.containers.count(container, item) | How many units of that item the container holds. |
game.containers.list(container) | The names of what the container holds. |
game.documents.has(document) | true if the player already has that journal document. |
game.data | Your own object, saved with the game (plain data only). |
game.random(a, b?) | Random integer between a and b (with one, from 0 to a). |
game.pick(list) | A random element of the list. |
game.log(...values) | Writes to the Play debugger Log (Code filter) and to the browser console. |
⏱ game.say(who, text) | A character says a line ("player" is the protagonist). Accepts [var:gold] and the other tags. |
⏱ game.narrate(text) | Voice-over. |
⏱ game.title(text, seconds = 3) | Full-screen title card. |
⏱ game.wait(seconds) | Waits. |
⏱ game.waitClick() | Waits for a player click. |
⏱ game.walkTo(who, target, wait = true) | Walks to a hotspot, scene object, character or entrance of the current scene. |
game.teleport(who, target) | Places them instantly. |
game.face(who, direction) | Turns them. |
game.faceTarget(who, target) | Turns them towards something. |
⏱ game.attach(who, point, what, opts?) | VERB Rig: the character carries an item (by its name) or an Assets image on a point ("hand", "head"…). An item is removed by itself when it leaves their inventory, unless { whileHeld: false }. The save remembers it. |
game.detach(who, point, opts?) | VERB Rig: puts down what is carried on the point (also the default); with { reset: true }, the default comes back. |
game.attachedAt(who, point) | VERB Rig: the name of the item or image a block or the code put on the point, or null (the default does not count). |
game.setSkin(who, skin) | Puts a skin on the character (VERB Rig or Spine), by its name; "default", the starting one. The save remembers it. |
⏱ game.animate(who, anim, loop = false) | Plays an animation. |
game.follow(who, leader) | Makes them follow another character (null: stop). |
⏱ game.goto(scene, entrance?, transition = "fade") | Changes scene. |
game.showProp(prop) | Shows a scene object. |
game.hideProp(prop) | Hides a scene object. |
game.setPropState(prop, state) | Changes the state of a scene object. |
game.enableHotspot(hotspot, on = true) | Turns a hotspot on or off. |
game.objective(objective, status = "done") | Changes a journal objective. |
⏱ game.dialogue(dialogue) | Starts a conversation and waits for it to end. |
⏱ game.runScript(script) | Runs another script and waits. |
⏱ game.cinematic(cinematic, wait = true) | Plays a cinematic (Cinematics plugin). |
⏱ game.endGame(text, retry = false) | Ends the game with that text. With retry, the end screen offers «Retry from just before» (back to the last checkpoint). |
game.checkpoint() | Saves a checkpoint (in memory; the engine sets one by itself when entering each scene). |
⏱ game.rewind() | Goes back to the last checkpoint (the whole game changes and the script ends). false if there is none or in a multiplayer room. |
game.sound(sound) | A sound effect. |
game.music(music) | Changes the music (null: stops it). |
game.loopSound(sound, untilStopped = true) | Loops a sound (with false, only in this scene). |
game.stopSound(sound, fade = 0.3) | Stops a sound (null: every loop). |
game.ambience(sound, fade = 1) | Changes the ambience of the current scene (null: silence). |
game.sceneAmbience() | Goes back to the scene ambience. |
game.musicVolume(volume, seconds = 1) | Raises or lowers the music (0–100) gradually. |
game.sceneSound(sound, on = true) | Turns a sound placed in the scene on or off. |
game.soundFrom(sound, target) | A sound that comes from something in the scene. |
game.acoustics(preset, mix?) | Changes the acoustics ("cave", "underwater", "radio", one of yours or "scene"). |
game.speechDuck(mode) | When the music goes down while someone speaks. |
game.vibrate(level = "medium") | Vibrates the phone (Android, with a finger) unless the player turned it off. |
⏱ game.camera.pan(target, seconds?) | Moves the camera to something. |
⏱ game.camera.panBy(dx, dy, seconds?) | Shifts the camera some pixels. |
game.camera.snap(target) | Places the camera instantly. |
game.camera.follow(who) | The camera follows a character. |
game.camera.stopFollow() | The camera stops following. |
⏱ game.camera.zoom(zoom, seconds?) | Zooms in (>1) or out (<1). |
⏱ game.camera.reset(seconds?) | Follows the protagonist again, without zoom. |
⏱ game.camera.shake(seconds, power?) | Shake. |
⏱ game.camera.fade(mode, seconds, color?) | Fade to black (out) or from black (in), or to another color. |
⏱ game.light(color, seconds?) | Changes the scene lighting ("#ffffff" is normal). |
game.hud(visible = true, cinemaBars = false) | Shows or hides the interface and the cinema bars. |
game.net.players | The names of who is in the room. |
game.net.count | How many players there are (1 without a room). |
game.net.isHost | true on the host (and without a room). |
game.net.me | My name in the room. |
game.net.list | Who is in the room, with their color, character (id), the scene each one is in and whether they are the host or you (empty without a room). |
game.net.send(message, data?) | Sends a message to the room (picked up by the “When the message arrives” event); with data, a short value that event saves in its variable. |
game.net.announce(text) | A notice for every player. |
⏱ game.do(sentence) | Runs steps written like the editor's human reading (es or en). |
⏱ game.check(sentence) | Evaluates a condition written like in the editor. |
⏱ game.block(type, params?) | Runs a block by its type with its values (by id). |
Related tutorial
On the editor's home screen, Tutorials: Randomness, data and lists (a chest with a random prize, a die, a counter in game.data and a rune lock with a list).