This document describes the API available to all JavaScript trigger and alias scripts.
The client interface is built with JQWidgets, so its widgets — including buttons, tabs, and windows — are available for use in scripts. jQuery is also available.
gwc
Provides access to Web Client features and managers from within trigger and alias scripts.
gwc.alias
Alias management interface.
gwc.alias.add(alias)
Adds a new alias.
| Parameter | Type | Description |
|---|---|---|
| alias | Alias | The Alias to add. |
Returns: boolean — True if added successfully.
gwc.alias.add({
value: "gr",
enabled: true,
script: { language: "javascript", data: 'gwc.connection.send("smile warmly");' },
});
gwc.alias.deleteByName(name)
Removes an alias by its name/pattern value.
| Parameter | Type | Description |
|---|---|---|
| name | string | The value field of the alias to remove. |
Returns: boolean — True if found and removed, false otherwise.
gwc.alias.deleteByName("gr");
gwc.alias.disable(name)
Disables a named alias so it no longer fires on matching input.
| Parameter | Type | Description |
|---|---|---|
| name | string | The name of the alias to disable. |
Returns: boolean — True if the alias was found and disabled, false otherwise.
gwc.alias.disable("gr");
gwc.alias.edit(alias)
Updates an existing alias, matched by its value field.
| Parameter | Type | Description |
|---|---|---|
| alias | Alias | An Alias with updated properties. |
Returns: boolean — True if the alias was found and updated, false otherwise.
const a = gwc.alias.find("gr");
a.script.data = 'gwc.connection.send("bow deeply to all");';
gwc.alias.edit(a);
gwc.alias.enable(name)
Enables a named alias so it fires on matching input.
| Parameter | Type | Description |
|---|---|---|
| name | string | The name of the alias to enable. |
Returns: boolean — True if the alias was found and enabled, false otherwise.
gwc.alias.enable("gr");
gwc.alias.find(name)
Finds an alias by its name/pattern value.
| Parameter | Type | Description |
|---|---|---|
| name | string | The value field to search for. |
Returns: Alias | null — The matching Alias, or null if not found.
const a = gwc.alias.find("gr");
if (a) gwc.output.append("Found: " + a.value, "script");
gwc.connection
Command sending interface.
gwc.connection.send(text)
Sends a raw command string to the MUD server, as if typed in the command input.
| Parameter | Type | Description |
|---|---|---|
| text | string | The command string to send. |
gwc.connection.send("kill dragon");
gwc.gmcp
Current GMCP data received from the server. Keys are GMCP variable names (e.g. 'Char.Vitals'); values are the parsed JSON payloads.
Type: JsonMap
gwc.localdata
Local key-value store held in the browser. Values persist across page reloads but are not synchronized to the server.
Type: JsonMap
gwc.music
Music and audio queues player interface.
gwc.music.clearQueue()
Clears the foreground music queue.
gwc.music.clearQueue();
gwc.music.queueUrl(url)
Adds the YouTube URL to the foreground music queue. If no foreground track is playing, interrupts the background music and plays it immediately.
| Parameter | Type | Description |
|---|---|---|
| url | string | The YouTube URL to play. |
gwc.music.queueUrl("https://www.youtube.com/watch?v=dQw4w9WgXcQ");
gwc.music.restart()
Restarts the current playing video to the beginning.
gwc.music.restart();
gwc.music.skip()
Skips the current foreground or background audio track and moves to the next.
gwc.music.skip();
gwc.output
Output window manipulation interface.
gwc.output.append(text, fgcolor, bgcolor)
Appends a new status line to the output window with optional color styling.
| Parameter | Type | Description |
|---|---|---|
| text | string | The text content to append. |
| fgcolor | string | A style name defined in `gwc.userdata.__styles__` (e.g. "exit", "script") or any CSS color value (e.g. "#ff0000", "rgb(255,0,0)"). Style names apply the full themed style; CSS values set the foreground color directly. |
| bgcolor? | string | A CSS background-color value. Omit or pass empty string for the default background. |
gwc.output.append("You have been hit!", "attack");
gwc.output.append("Treasure found!", "#ffd700");
gwc.output.color(fgcolor, bgcolor)
Applies a foreground and background color to the most recently received output line.
| Parameter | Type | Description |
|---|---|---|
| fgcolor | string | A style name defined in `gwc.userdata.__styles__` (e.g. "exit", "script") or any CSS color value (e.g. "#ff0000", "rgb(255,0,0)"). Style names apply the full themed style; CSS values set the foreground color directly. |
| bgcolor? | string | A CSS background-color value. Omit or pass empty string for no change. |
gwc.output.color("script");
gwc.output.color("#ff4444");
gwc.output.colorword(word, fgcolor, bgcolor)
Highlights all occurrences of a word in the most recently received output line.
| Parameter | Type | Description |
|---|---|---|
| word | string | The word to highlight (matched as a whole word). |
| fgcolor | string | A style name defined in `gwc.userdata.__styles__` (e.g. "exit", "script") or any CSS color value (e.g. "#ff0000", "rgb(255,0,0)"). Style names apply the full themed style; CSS values set the foreground color directly. |
| bgcolor? | string | A CSS background-color value for the highlight. Omit or pass empty string for default. |
gwc.output.colorword("dragon", "attack");
gwc.output.colorword("treasure", "#ff4444");
gwc.output.getLine(index, html)
Returns the content of a stored output line by 1-based index.
| Parameter | Type | Description |
|---|---|---|
| index | number | The 1-based line number. Index 1 is the first line ever received; `gwc.output.lineCount()` is the most recent. |
| html? | boolean | When true, returns the inner HTML of the line. When false (default), returns plain text. |
Returns: string | null — The line content as a string, or null if the index is out of range.
const last = gwc.output.getLine(gwc.output.lineCount());
const lastHtml = gwc.output.getLine(gwc.output.lineCount(), true);
gwc.output.lineCount()
Returns the number of stored output lines.
Returns: number — The count of lines received and stored so far. Returns 0 before any output arrives.
const n = gwc.output.lineCount();
gwc.output.append("Lines so far: " + n, "script");
gwc.output.replace(toFind, replacement, html)
Replaces text in the most recently received output line.
| Parameter | Type | Description |
|---|---|---|
| toFind | string | The text to find. Must not be empty. |
| replacement | string | The replacement text. Must not be empty. |
| html? | boolean | When true, operates on the raw HTML of the line rather than its plain text. |
gwc.output.replace("you", "YOU");
gwc.output.replace("you", '<span class="friends">YOU</span>', true);
gwc.output.setLine(index, content, html)
Replaces the content of a stored output line by 1-based index. Prints a script error message if the index is out of range.
| Parameter | Type | Description |
|---|---|---|
| index | number | The 1-based line number. Index 1 is the first line ever received; `gwc.output.lineCount()` is the most recent. |
| content | string | The replacement content. |
| html? | boolean | When true, treats content as HTML. When false (default), treats it as plain text. |
gwc.output.setLine(gwc.output.lineCount(), "-- replaced --");
gwc.output.setLine(1, '<span class="error">ERROR</span>', true);
gwc.tabs
Browser tab notification interface.
gwc.tabs.notify(title)
Updates the browser tab title to draw attention to new activity.
| Parameter | Type | Description |
|---|---|---|
| title | string | The title text to display in the browser tab. |
gwc.tabs.notify("PROGRESS");
gwc.trigger
Trigger management interface.
gwc.trigger.add(trigger)
Adds a new trigger to the trigger list.
| Parameter | Type | Description |
|---|---|---|
| trigger | Trigger | The Trigger object to add. |
Returns: boolean — True if the trigger was added successfully.
gwc.trigger.add({
name: "hp tracker",
type: "regexp",
value: "Your HP is (\\d+)",
caseInsensitive: false,
enabled: true,
script: { language: "javascript", data: "gwc.localdata.hp = args[1];" },
});
gwc.trigger.deleteByName(name)
Removes a trigger by name.
| Parameter | Type | Description |
|---|---|---|
| name | string | The name of the trigger to remove. |
Returns: boolean — True if the trigger was found and removed, false otherwise.
gwc.trigger.deleteByName("combat tracker");
gwc.trigger.disable(name)
Disables a named trigger so it no longer fires on matching output.
| Parameter | Type | Description |
|---|---|---|
| name | string | The name of the trigger to disable. |
Returns: boolean — True if the trigger was found and disabled, false if no trigger with that name exists.
gwc.trigger.disable("combat tracker");
gwc.trigger.edit(trigger)
Updates an existing trigger by name, replacing its properties with those of the provided object.
| Parameter | Type | Description |
|---|---|---|
| trigger | Trigger | A Trigger object containing the updated properties. Matched by its name field. |
Returns: boolean — True if the trigger was found and updated, false otherwise.
const t = gwc.trigger.findByName("hp alert");
t.value = "Your HP is (\\d+)";
gwc.trigger.edit(t);
gwc.trigger.enable(name)
Enables a named trigger so it fires on matching output.
| Parameter | Type | Description |
|---|---|---|
| name | string | The name of the trigger to enable. |
Returns: boolean — True if the trigger was found and enabled, false if no trigger with that name exists.
gwc.trigger.enable("combat tracker");
gwc.trigger.findByName(name)
Finds a trigger by its name.
| Parameter | Type | Description |
|---|---|---|
| name | string | The name to search for. |
Returns: Trigger | null — The matching Trigger, or null if not found.
const t = gwc.trigger.findByName("hp alert");
if (t) gwc.output.append(t.value, "script");
gwc.trigger.findByPattern(pattern)
Finds a trigger by its pattern value.
| Parameter | Type | Description |
|---|---|---|
| pattern | string | The pattern string to search for. |
Returns: Trigger | null — The matching Trigger, or null if not found.
const t = gwc.trigger.findByPattern("^You are hungry");
if (t) gwc.trigger.enable(t.name);
gwc.userdata
Persistent key-value store whose data is stored on the server and shared across all sessions on the same account. Changes are uploaded in batches, so if `userdata` is large and updated frequently, this can cause performance issues for the user. For temporary values or data that changes often (such as tracking which step a script is currently on), prefer `gwc.localdata`, which is stored only in the browser and avoids the upload overhead.
Type: UserData
mud
Provides direct access to the MUD connection layer from within trigger and alias scripts.
mud.connection
The raw WebSocket connection to the Genesis server. Prefer mud.disconnect() to close the connection.
Type: WebSocket
mud.disconnect()
Closes the connection to the MUD server.
mud.disconnect();
mud.gmcp
Record of all GMCP variables received from the server since connection. Keys are GMCP variable names; values are the last received JSON payload for that variable.
Type: MudGmcpData
mud.is_connected()
Returns true if the WebSocket connection to the MUD server is currently open.
Returns: boolean — True if connected, false otherwise.
if (!mud.is_connected()) gwc.output.append("Not connected.", "error");
mud.isConnecting()
Returns true if the WebSocket connection is currently being established.
Returns: boolean — True if connecting, false otherwise.
if (mud.isConnecting()) gwc.output.append("Still connecting...", "script");
mud.Process
Low-level interface for injecting data into the MUD processing pipeline.
mud.Process.incoming(data)
Injects a line of text into the output window as if received from the server.
| Parameter | Type | Description |
|---|---|---|
| data | string | The text line to inject. |
mud.Process.incoming("You have been killed by a dragon.\n");
mud.Process.incoming_gmcp(data)
Injects a raw GMCP data string as if received from the server.
| Parameter | Type | Description |
|---|---|---|
| data | string | A raw GMCP data string in the format 'VariableName {json}'. |
mud.Process.incoming_gmcp('Char.Vitals {"hp":100,"mp":80}');
mud.Process.outgoing(data)
Sends a raw command string to the MUD server, bypassing alias processing.
| Parameter | Type | Description |
|---|---|---|
| data | string | The command string to send. |
mud.Process.outgoing("kill dragon");
mud.Process.outgoing_gmcp(name, data)
Sends a GMCP message to the MUD server.
| Parameter | Type | Description |
|---|---|---|
| name | string | The GMCP variable name (e.g. 'Core.Hello'). |
| data | JsonObject | The payload value, which will be JSON-serialized before sending. |
mud.Process.outgoing_gmcp("Core.Hello", { client: "MyClient", version: "1.0" });
wait
wait(args)
Pauses script execution for a specified number of seconds. Use with await: `await wait(5)` pauses for 5 seconds.
| Parameter | Type | Description |
|---|---|---|
| args | number[] | Pass a single number of seconds to wait. Defaults to 600 (10 minutes) when omitted. |
Returns: Promise<void>
await wait(3);
wait(3).then(() => gwc.connection.send("smile warmly"));
waitUntil
waitUntil(pattern, timeout?)
Pauses script execution until MUD output contains a line matching the given pattern, or until the timeout expires.
| Parameter | Type | Description |
|---|---|---|
| pattern | string | RegExp | A string or RegExp to match against MUD output lines. Strings are converted to a RegExp automatically. |
| timeout? | number | Maximum seconds to wait before rejecting with a timeout error. Defaults to 600 (10 minutes). |
Returns: Promise
await waitUntil("You stop bleeding");
await waitUntil(/^Your HP is (\d+)/, 30);
waitUntil("You stop bleeding")
.then(() => gwc.connection.send("sigh relieved"))
.catch(() => gwc.output.append("Timed out waiting to stop bleeding.", "error"));
args
args
An array of string match groups captured by the trigger or alias pattern. `args[0]` is the full match; `args[1]`, `args[2]`, etc. are capture groups in order.
Type: string[]
Types
Alias
An alias that matches typed commands and executes a script in response.
{
value: "gr",
enabled: true,
script: {
language: "javascript",
data: "gwc.connection.send('smile warmly');"
}
}
| Property | Type | Description |
|---|---|---|
| enabled | boolean | Whether this alias is currently active and will process matches. |
| script | object | The script to execute when this alias matches. |
| script.data | string | The raw script source code. |
| script.language | string | The script language: 'javascript' or 'plain'. |
| script.user_function | any | The compiled script function. Set automatically by the system; do not assign this manually. |
| value | string | The alias name. This is what the user types. |
Trigger
A trigger that fires a script when MUD output matches a pattern.
{
name: "hp tracker",
type: "regexp",
value: "^HP: (\\d+)/(\\d+)",
caseInsensitive: false,
enabled: true,
script: {
language: "javascript",
data: "gwc.localdata.hp = args[1];"
}
}
| Property | Type | Description |
|---|---|---|
| caseInsensitive | boolean | When true, pattern matching ignores case differences. |
| enabled | boolean | Whether this trigger is currently active and will fire on matching output. |
| name | string | The unique name identifying this trigger. |
| script | object | The script to execute when this trigger fires. |
| script.data | string | The raw script source code. |
| script.language | string | The script language: 'javascript' or 'plain'. |
| script.user_function | any | The compiled script function. Set automatically by the system; do not assign this manually. |
| type | string | The matching mode: 'regexp' for regular expression matching, or 'string' for literal string matching. |
| value | string | The pattern to match against. Interpreted as a regular expression or literal string depending on the type field. |
UserData
A persistent key-value store synchronized via GMCP. Values survive page reloads and are shared across sessions on the same account.
| Property | Type | Description |
|---|---|---|
| __settings__? | JsonMap | A map of system settings that control web client behavior. These settings are also written to local storage so they are available before login. Most settings are managed through the Settings window, but can also be read or modified directly in scripts. |
| __styles__? | JsonMap | A map of style names to CSS style strings defining custom styles for the web client.
Styles defined here appear automatically in the Settings window and can be toggled on or off.
Define your custom styles here rather than inserting style tags directly. |