Scripts

Posted by Kyle Hankinson June 16th, 2026


Scripts

The Scripts section is where you keep reusable JavaScript. Instead of copying the same code into every trigger and alias, you write a function once in a script and pull it in wherever you need it.

Every trigger and alias runs in its own JavaScript context, so the functions you define in a script are not available everywhere automatically. You make them available by including the script.

include() and require()

include(scriptName)

The include function loads another script by name and makes everything it defines available to the current trigger, alias, or script. scriptName is the title of the script as it appears in the Scripts list, and is not case sensitive.

require(scriptName)

require is identical to include. Use whichever reads better to you.

A script is only ever included once per run, so it is safe to include the same script from several places, and scripts may include other scripts.

Using a script from a trigger or alias

Create a script named Combat with a couple of helpers:

// Script: Combat
function herb(name) {
    command('get ' + name + ' from pack');
    command('eat ' + name);
}

function quaff(potion) {
    command('quaff ' + potion);
}

To use it from a trigger, include the script at the top of the action, then call the function. (Capture groups from the trigger's pattern are available via textOf(1), textOf(2), and so on. See the Regular expression tips post.)

// Trigger action. Pattern: ^You feel hungry
include('Combat');
herb('bloodroot');

An alias works exactly the same way. Here the first capture group of the alias pattern is passed straight through:

// Alias action. Pattern: ^h (\w+)
include('Combat');
herb(textOf(1));

Because the include runs first, herb is ready to call on the lines that follow.

Reloading after edits

When you change a script, reload so your triggers and aliases pick up the new code:

#reload

Reloads every trigger, alias, and script from disk and reports how many of each were loaded.

Tips

  • Group related helpers into one script (for example a Combat script and a Travel script) and include only what each trigger needs.
  • Includes are resolved when the action is prepared, so there is no measurable cost to including a script you use often.
  • See the Functions post for the full list of built-in functions you can call from your scripts, and Console commands for the # commands.

Tags: Scripting