Repository navigation
Custom Actions
registerAction(type, def) adds an action type to the Add action list (under Other unless you give a group). Using the type of an existing action replaces it, so prefix yours with your module id.
tt.registerAction("my-module.shout", {
label: "Shout", // shown in the list (an i18n key works too)
icon: "fa-solid fa-bullhorn", // optional, default "fa-solid fa-gear"
group: "game", // optional: "rolls", "scene", "game", "flow" or "other" (default)
fields: [ // optional: what the editor shows, stored on the action under each key
{ key: "text", type: "text", label: "Text", default: "Who goes there?" },
{ key: "loud", type: "checkbox", label: "Loud", default: false },
{ key: "volume", type: "number", label: "Volume", default: 1, min: 0, max: 1, step: 0.1, showIf: a => a.loud }
],
summary: a => a.text, // optional: short text on the collapsed card; (action, context) => string
run: async (action, ctx) => { // runs on the GM's client
await ChatMessage.create({ content: action.loud ? action.text.toUpperCase() : action.text });
}
});key, type, label (required), and optional default, hint, placeholder and showIf(action) (show the field only when it returns true).
| Type | Extra options |
|---|---|
text |
|
textarea |
|
formula |
|
number |
with min, max, step
|
checkbox |
|
select |
with options: { value: label }, or a function (context) => ({ value: label })
|
file |
with fileType, e.g. "audio" or "imagevideo"
|
doc (one UUID) |
with docTypes, e.g. ["Token", "Tile"]
|
docs (an array of UUIDs) |
with docTypes, e.g. ["Token", "Tile"]
|
The editor calls an options function and summary with context = { tile, scene }: the tile being edited and its scene (for options that depend on the scene, like the areas of the Show / hide canvas effect area action). A saved value a select no longer offers stays selected, shown as Missing.
A field with key: "target" and the default "trigger" starts on "inside" when it is added to a round start or initiative count trigger. Use the same target values as the module's actions (trigger, inside, picked, patch) if you want that.
run(action, ctx): action holds your field values (numbers as numbers, checkboxes as booleans), ctx is the same object the fire hook gets (see API). Set ctx.stop = true to skip the rest of the trigger's actions. If run throws, the GM gets a "failed" notification and the next action runs.
branches: true gives the action On success / On failure lists, stored as action.success and action.fail. Running them is up to your run: pass the list to tt.runActions(list, ctx), the function the module runs every action list with. Give it a copy of ctx with depth one higher (nesting stops a few levels down); vars you add there become placeholders in the branch's texts.
tt.registerAction("my-module.coinFlip", {
label: "Coin flip",
branches: true,
run: async (action, ctx) => {
const heads = Math.random() < 0.5;
const sub = { ...ctx, depth: ctx.depth + 1, vars: { ...ctx.vars, result: heads ? "heads" : "tails" } };
await tt.runActions(heads ? action.success : action.fail, sub);
}
});Register it on every client, from your setup or ready hook (the API exists after this module's init). The GM's client needs it to run the action and to show it in the editor; a trigger with an unregistered action type skips that action.
Dxcufgb's Workshop: every Foundry VTT project, video and changelog in one place · Support on Ko-fi · MIT License
Using it
For module authors
Help