Talking, emoting, and messaging

Most of what a script does that players actually see is text: a mob speaks, an object hums, a room whispers. There are several ways to produce that text, and choosing the right one — and building the string well — is the heart of a lively script.

The two string forms

Every message starts with a string, and the form you quote it in decides whether it interpolates:

do "say Hello, [name $actor]!"     # -> say Hello, Puff!
do 'say The $ sign is literal.'    # -> say The $ sign is literal.

Reach for single quotes for fixed text or anything containing a literal $ or [; reach for double quotes whenever you want to splice values in. Both forms accept the escapes \n (newline), \t (tab), and \\; inside double quotes you also escape \$ and \[ to keep them literal, and \" for a quote.

Interpolation and the braced form

Inside "...", a bare $name runs only while the following characters are letters, digits, or _. When text must butt right up against the value, use the braced ${name} form to mark where the name ends:

let n 3
do "say I have ${n}coins."          # -> I have 3coins.   ('coins' kept)
do "say That is $n total."           # -> That is 3 total.

Any value converts to text for interpolation — that is the language's one automatic conversion. Interpolate the descriptive form for display (name, level), not a raw entity reference:

do "say [name $actor] is level [level $actor]."

Building a string is interpolation: write the pieces into a "..." string and let $name and [cmd] fill them in.

Making the owner speak and act — do

do makes the owner mob run a command line, exactly as if a player at its keyboard had typed it. This is how a mob says, emotes, smiles, or runs any game command:

after command (wave) {
  do "wave $actor"
  do "say Greetings, traveller."
}

Embed a newline to run several commands in one call:

after enter {
  do "stand\nsay Welcome to my shop.\nsmile"
}

do needs a mobile owner; from an object or room script it does nothing — use echo/emit there instead. To run a command without its usual output reaching the room, use silently:

handle command (examine) {
  silently "look $actor"     # the owner looks, the room sees nothing
}

Sending text directly — echo

echo sends one fixed line to a target without running a command. The target may be a creature, a room, the string "room" (the owner's room), or "zone" (every player in the owner's zone):

handle command (pray) {
  echo $actor "A warmth settles over you alone."
  echo "room" "The candles flicker as $actor prays."
}

echo works from any owner, including objects and rooms, which makes it the workhorse for non-mob scripts.

Per-observer messages — emit

emit runs a message through the game's act system, so each onlooker sees it phrased from their own viewpoint, with pronouns and verb agreement filled in. Write the message single-quoted so the act codes (which start with $) survive:

after command (dance) {
  emit room '$n spins in a graceful circle, $s eyes shining.'
}

The actor sees "You spin in a graceful circle, your eyes shining," while onlookers see "Puff spins…" The common codes are $n (actor name), $N (victim name), $e/$s/$m and $E/$S/$M (actor/victim pronouns), and $%/$^ (verb-agreement suffix). The <type> selects the audience: room, char (actor only), vict (victim only), notvict, or zone.

To mix script interpolation with literal act codes, use a double-quoted string and escape each act $:

after command (point) {
  emit room "\$n points gravely at [name $actor]."
}

Here the script fills in [name $actor] while \$n is left for the act system to render per viewer.

Pronouns — he / him / his

When you build a sentence by hand rather than through emit, the pronoun built-ins give the right word for a creature's gender: he (subject), him (object), his (possessive):

after command (bow) {
  echo "room" "$self bows to [name $actor]; [he $actor] returns it. $self offers [him $actor] a hand, lowering [his $actor] head."
}

For a male actor this renders "…he returns it. offers him a hand, lowering his head."

Driving another creature — force

force makes a different creature run a command. Where do drives the owner, force drives whoever you name:

handle command (kneel) {
  force $actor "say I kneel before you, $self."
}

Varying responses — randomly

A mob that always says the same thing feels mechanical. randomly picks one of several branch blocks at random, the branches separated by the literal marker or:

after command (greet) {
  randomly {
    do "say Well met!"
  } or {
    do "say A fine day, is it not?"
  } or {
    do "emote dips into a theatrical bow."
  }
}

Each branch is an ordinary block, so it can do as much as you like.

Changing the standing description — ldesc

ldesc rewrites the line others see for the owner where it stands (a mob) or lies (an object) — useful for reflecting state:

after command (rest) {
  ldesc "Puff the dragon dozes here, wreathed in pipe smoke."
}

It applies to this instance only; the prototype and other copies are untouched.

See also