A module is the quickest way to add scripting to one server. It is a TypeScript or JavaScript file in Documents/smudgy/<server>/modules/. Every file at the top level of that folder loads when a session for that server starts or reloads. Modules are your own unrestricted code; do not paste in code you have not reviewed.
Open the server's Automations window, choose Create module, and name the file my-automations.ts. Paste this code into the editor and save it:
import { createAlias, createTrigger, echo } from "smudgy:core"; echo("My automations loaded."); createAlias(/^greet (?<name>.+)$/, ({ name }) => { return `say Hello, ${name}!`; }); createTrigger(/^You are hungry\.$/, () => { return "eat bread"; });
The alias replaces greet Pat with say Hello, Pat!. The trigger sends eat bread when the matching line arrives from the MUD. Script-created automations are rebuilt on every reload, so the module should register them each time it loads.
After saving, reload the session's scripts if the window does not do so automatically. The My automations loaded. line confirms that the top level ran. The alias and trigger should also appear beneath the module in Automations; that list is a read-only view of what the module registered.
See Automations for patterns, capture groups, options, and the handles returned by the create* functions.
Smudgy creates a TypeScript project beside your scripts. An editor with TypeScript support can therefore autocomplete imports, check argument types, and show the same API comments used by the reference.
The built-in editor is useful for small changes. An external editor is more comfortable once a module grows beyond a few automations. Edit the same file in only one editor at a time so a later save does not overwrite newer work.
Use a module for personal scripts tied to one server. When the code needs versions, dependencies, install-time options, or distribution to other players, turn it into a package.
For the complete API, start at the script reference.