ScriptingVariables, DeadScript and event triggers in Arcana

Arcana remembers things for you. Put a name in a variable once, and every alias, trigger, hotkey and button can use it. When a plain command isn't enough, write a line of DeadScript, the same language the realm's creatures are scripted in.

Scripting runs in Arcana, the client at /play/. A telnet client gets the same game, with its own scripting.

The rest of the client is on the Arcana page. Aliases, triggers, hotkeys, buttons and variables are all in Settings, in the Arcana menu (Alt+A).

Variables in your commands

A variable is a name with a value, such as target holding orc. Write @target in any command and Arcana puts the value in before the command goes to the game. This works in lines you type, in aliases, in a trigger's commands, in hotkeys, in buttons, and in links you click.

@<name>The value of the variable <name>. A name is letters, digits and _, starting with a letter or _.
@{<expression>}Runs <expression> as DeadScript and puts in what it gives: say I have @{1 + 2} coins sends say I have 3 coins.
@@A plain @.

An @ that isn't a variable stays as you typed it. So say mail me@home @ 3pm goes out as it is, unless you have a variable called home. A lone @, an @ before a digit, and an @{ that never closes stay too.

A list reads as its items joined with commas, a whole number has no decimal point, and an empty value (null) reads as nothing. If an @{…} fails, nothing is sent and Arcana tells you why: Not sent: @{nosuch.x}: ….

Nothing is filled in while Arcana keeps out of the way: at a password, during the login, and in the game's editor and pager. A line that starts with \ goes out exactly as typed.

The /js line

Type these at the command line.

/js <code>Runs <code> as DeadScript. If the line is one expression, Arcana shows its value: /js vars.target shows orc. Errors show as /js: ….
/js varsLists this character's variables.
/js set <name> <value>Sets @<name> to <value>, as text.
/js unset <name>Removes @<name>.

/js set always stores text. After /js set n 1, the command say @{vars.n + 1} sends say 11, because text plus a number joins them. To store a number, a list or an object, set it in code: /js vars.n = 1, and then say @{vars.n + 1} sends say 2.

A /js line skips your aliases. Functions and vars you make with /js last until you close the page; only vars is saved. The last ; of a typed line may be left off.

An alias, hotkey or button can hold a /js line too. From an alias, /js set and /js unset work quietly, without a message.

What a script can use

send(<command>)Sends <command> to the game as it is, without your aliases, and shows it as you would see a typed command. Text with several lines sends one command per line.
echo(<text>)Shows <text> in the game window, for you only. It can be plain text or Quill, so bold, colours and help links all work. Your triggers never see these lines.
link(<text>, <command>)A link for echo: it shows <text>, and a click runs <command> as if you typed it. The command is one line of at most 400 characters.
varsThis character's variables: vars.target is @target. A change is saved as soon as the script ends.
Mud.dice(<count>, <sides>)Rolls dice, exactly as the game does. Mud.dice(<sides>) rolls one.
Mud.capForLevel(<level>)The most experience one kill can give at <level>.
Mud.possessionDesc(<owner>, <thing>)The game's possessive: Mud.possessionDesc("Jane", "a sword") is Jane's sword.

The whole standard library comes too: String, Array, Math and Date, with the game's own extras such as "orc".plural(), like, Math.between and the array methods has, unique and random. They behave exactly as they do in the game.

The game's own objects belong to the world, so they aren't here: self, Room, Char, Obj, Mud.useCharge and the rest. Using one stops the script with a clear message, such as self only runs in the game.

DeadScript in short

DeadScript is the realm's scripting language: an early JavaScript, with the game's own extras. The creatures, rooms and objects of Tera run on it, and Arcana runs the very same language. A builder who writes creature scripts already knows how to script the client, and the other way round. The full reference is in the game's help, under JavaScript.

Triggers

A trigger's When is either The game says a line, or one of twelve events. An event trigger needs no pattern: it fires when the thing happens. Where the event is about something, such as an aura or a person, you can give a pattern, and the trigger fires only when that matches. Leave it empty for any.

WhenThe pattern is tried onNames
A buff or debuff wears off youits name<aura> <type>
A buff or debuff lands on youits name<aura> <type>
A fight startsthe enemy<enemy>
A fight ends
Someone tells you somethingwho told you<who> <text>
Someone talks on a channelthe channel<channel> <who> <text>
You enter another roomthe room's name<room> <num>
You die
You gain a levelthe new level<level>
Your character is in the gameits name<name>
The connection opens
The connection closes

The names work in the trigger's commands and values like a pattern's own <names>: on a tell, <who> is who told you. An event has no line, so an event trigger can't highlight, hide, copy to the chat window or make a link. When the connection opens or closes, a trigger can play a sound or notify you, but sends nothing.

Two actions belong to scripting:

Text from the game stays text. What a trigger catches from a game line can't fill a variable into a command or run code: an @ in it stays a plain @. A trigger can't run /js code; it can use Set a variable, or /js set in its commands. Only link() and Make a link make links that run commands, so a line from the game can never pretend to be one.

Settings › Variables

Settings › Variables lists the variables of the character you are playing. Change a value in place, add one with its name and value, or remove one with ×. Each character keeps its own variables.

Limits

The rules on scripts still apply. Triggers are welcome; a set of them that plays your character while you are away is not.

Examples

A sticky target

Make two aliases in Settings › Aliases:

t/js set target $1
kkill @target

Type t orc once. From then on k sends kill orc, in this session and the next, until you pick a new target. A hotkey with kill @target works the same way.

Sums in a command

say I have @{1 + 2} coins

Sends say I have 3 coins. With /js vars.gold = 40, say I have @{vars.gold * 2} coins sends say I have 80 coins.

When a buff wears off

A new trigger, set up like this:

When sanctuary falls, you hear it, and @lost holds its name. A hotkey with cast '@lost' then puts back whatever fell last. Leave the name empty and the trigger fires for every buff and debuff.

A line you can click

/js echo("<c type=\"danger\">Sanctuary has worn off.</c> " + link("Cast it again", "cast 'sanctuary'"))

Shows Sanctuary has worn off. in the danger colour, followed by a link, Cast it again. A click on the link sends cast 'sanctuary'. Put the line in a button or a hotkey to call it up whenever you need it.