Code macros: the API

What a code macro can read, which functions it has and every action it can ask for, with its arguments.

A code macro is a piece of JavaScript that does not touch the world: it reads table data and returns a list of actions, the same ones used by the steps of easy mode and by event zones. The usual engine runs them, with your permissions, exactly as if you had pressed them by hand. This page is the reference for what the code can read and the actions it can ask for; it comes from the engine itself. How to create a macro is in Macro builder and how it is used at the table in Macros at the table.

How it runs

The code runs in an isolated environment, with no access to the browser, the network, timers or other people's data. Dice are rolled by the house engine: when the script asks for a roll, the table resolves it and the script runs again from the start with that result, so there is no clock or randomness of its own inside. That is why there are caps:

  • At most 24 distinct rolls per macro (each one costs a pass).
  • At most 60 actions returned; the rest are dropped and the log says so.
  • A time cap per pass; if it is exceeded, the macro stops and warns.
  • Anything not in the action catalog is dropped and named in the warning.

Functions

The ones that always exist inside the code:

FunctionWhat it does
dados('2d6+3')Rolls that expression with the house engine and returns { total, detalle, formula }. It posts nothing to the chat; for that, use the tirar action.
azar()A number from 0 to 1 from the same source (Math.random is the same thing).
hacer(tipo, arguments)Asks for an action by name. Every catalog action also has a shortcut with that same name: mensaje({ texto: 'Hello' }).
ficha.get('atributos.dex')Reads a sheet value by path, ignoring accents and case. If it does not exist it returns undefined and notes it in the log; it never makes a value up.
ficha.tiene(path)Tells whether the sheet has that datum.
inventario()The sheet inventory: { id, nombre, cantidad, peso, peso_total, equipado, categoria }.
cuantos('Potion')How many units of an item are carried, by name.
dinero() · dinero('gold')All the money, or one currency.
console.log(...)Writes to the macro log (up to 100 lines).

Data it can read

Read-only variables; changing them changes nothing outside the macro.

VariableWhat it holds
yoWhoever launches the macro.
tokenTheir token on the map.
tokensThe tokens of the scene.
objetivoThe marked target.
fichaThe sheet of whoever launches it.
campanaCampaign data.
escenaThe current scene.
combateThe combat, if there is one.
murosWalls and doors.
lucesLights.
zonasEvent zones.
jugadoresWho is at the table.

Actions it can ask for

Each row is a name used as a function (dano({ formula: '2d6' })) or with hacer('dano', ...). The third column gives the argument names. The ones not listed here are only written by hand in a text macro.

The table

NameWhat it doesArguments
mensajesay something in the chattexto
tirarroll diceformula, etiqueta, detalle
fxplay a visual effectefecto, escala, permanente
pausarpause the game (notice to the table)texto
texto_flotantefloating text over the maptexto
sonarplay a sound effecturl
musicachange the music listlista
experiencialaunch an experience to the tablebiblioteca, url, titulo
momentolaunch a scene momentmomento
presentar_apppresent a puzzle (and wait)app_id
mostrar_entradashow a World entry to the tableentrada
revelar_contenedorreveal a container (loot) to the tablecontenedor
mostrar_escenashow a scene (image or video)url, titulo, bucle, modo
reproducir_pistaplay a music tracklista, pista
poner_escenaput a scene liveescena
cartasmove cards from a deckbaraja, accion, cantidad
carta_jugarplay a card from my handbaraja, carta
carta_descartardiscard cards from my handbaraja, carta, cantidad
carta_zonatake a card from my hand to a zonebaraja, carta, zona
carta_girarturn or straighten table cardsbaraja, carta, modo
carta_mostrarshow a card from my hand to the tablebaraja, carta
carta_dargive a card to another playerbaraja, carta
tirada_cartasroll with cardsbaraja, cantidad, de, agregacion, despues, etiqueta
carta_recetacard recipebaraja, receta

The map

NameWhat it doesArguments
abrir_puertaopen a doormuro
cerrar_puertaclose a doormuro
cerrar_con_llavelock a doormuro
animacionturn a map animation on or offprop, accion
cambiar_plantachange floorplanta
oscuridadchange the scene darknessnivel
climachange the scene weatherclima, intensidad
pantallascreen effect (flash, shake, fade, vignette...)efecto, fuerza, segundos, color
luzturn a light on or offluz, intensidad
ocultar_tokenhide a token—
mostrar_tokenshow a token—
mover_tokenmove a token to a squarex, y
cambiar_fondochange the map backgroundurl
cambiar_mapatake the table to another mapmapa
mover_camarabring everyone's view to a pointdonde, x, y
crear_tokencreate a tokennombre, clase, x, y, cantidad, pv, ca, tamano
borrar_tokenremove a token from the map—
actualizar_tokenchange token datanombre, pv, pv_max, ca, tamano, visible, rotacion
crear_murocreate a wall or doorx1, y1, x2, y2, puerta
actualizar_murochange a wall or doormuro, puerta, color, grosor
borrar_muroremove a wall or doormuro
crear_luzcreate a lightx, y, radio, intensidad, color
actualizar_luzchange a lightluz, radio, intensidad, color
borrar_luzremove a lightluz
nieblareveal or hide fogmodo, x, y, radio, ancho, alto
capa_visibleshow or hide a layer in my viewcapa, visible
centrar_tokencenter my view on a creaturetoken_id

Combat and sheet

NameWhat it doesArguments
usar_accionuse one of your actionsaccion
danodeal damageformula, tipo_dano, efecto
curarhealformula, efecto
condicionapply a conditioncondicion
quitar_condicionremove a conditioncondicion
empezar_combatestart combatgrupo, modo
pedir_tiradaask for a rolltexto, salvacion, cd, formula, tipo_dano
ficha_ponerset a value on the sheetcampo, valor
ficha_sumaradd to (or subtract from) a sheet valuecampo, valor
inventario_dargive an itemnombre, cantidad, peso, limite_peso
inventario_quitartake an item awaynombre, cantidad
dinero_sumaradd (or subtract) moneycantidad, moneda
esperar_turnowait for a turn (and go on)hasta, ronda
siguiente_turnomove to the next turnsentido
anadir_a_combateadd to combat—
quitar_de_combatetake out of combat—

Script control

NameWhat it doesArguments
armar_zonaarm another zonezona
desarmar_zonadisarm another zonezona
revelar_zonareveal a zone to the tablezona
disparar_zonatrigger another zonezona
ejecutar_macrorun a macromacro
siif... (and otherwise...)cond, entonces, sino
repetirrepeat several timesveces, acciones
esperarwait a whilesegundos
esperar_eventowait for something to happenevento, si, segundos, si_no_llega
var_ponerstore a variablenombre, alcance, modo, valor
preguntarask someonepregunta, forma, opciones, campos, elegir_min, elegir_max, min, max, clave, destino, segundos, si_no_responde

An example

Roll an attack and, on a hit, deal damage:

var ataque = dados('1d20+5');
mensaje({ texto: 'Attack: ' + ataque.total });
if (ataque.total >= 15) {
  dano({ formula: '1d8+3', tipo_dano: 'slashing' });
}

Common problems

"This macro asks for more than 24 rolls." Split the rolls across several macros or use a single dice expression (4d6kh3).

"The sheet has no..." The path does not exist in your system; check the macro log and the real field names.

"An action is dropped." Its name is not in the catalog; the warning names it.

See also

Macro builder, Macros at the table, Event zones: make the map do things by itself, Chat commands and dice, Formulas and functions.

All Roliando guides