FMud Scripting

Check out my screencasts if you are looking for tutorial information on how to use the IRE Flash client.

FMud now includes support for the creation of aliases, triggers and keypad macros as well as scripting with Javascript. These are accessed from tabs within the settings window.

Basic Use

Click the new button to create an alias or trigger. You can click on a cell to edit it, or in the case of the pattern and send cells you double click to bring up an edit window. You cannot create new macros, however you can edit the send box to control what is sent to the server when pressing the keypad key. Aliases, triggers and macros can be saved and loaded as text files in xml format.

Enter the pattern you wish to match in the pattern cell using * as a wildcard for any matches in the pattern. Enter the text you wish to send to the server when the pattern matches into the send cell. You can use %1, %2… %n as wildcards to reference the first, second… nth wildcard matches in the pattern.

The regexp option enables more sophisticated pattern matching using regular expressions. Enabling the script option allows you to use Javascript code in the send cell for more complex scripting.

Options

Pattern

This is the string to match. You can use * to match on anything, unless regexp is enabled in which case you need to specify a correct regular expression, for example (.*?) instead of *.

Send

When the script option is false this text is sent to the server. You can use %1, %2, %3 etc. to reference the first, second, third etc. matches in the pattern. You can separate commands using a semi colon, and for macros (but not aliases or triggers) the send box can contain an alias. If script is enabled then this text is instead executed as code. The script syntax is the same as Javascript.

Enabled

If false the alias/trigger won’t be evaluated. There are also global enable/disable aliases and triggers options in the preferences tab.

Script

If false then any text entered in the send box is sent to the server when an alias or trigger matches. If set to true this text is instead evaluated as code.

Name

The name can be used to refer to a single alias/trigger in combination with the enable and disable functions. Names should be unique.

Group

The group can be used to refer to multiple alias/triggers in combination with the enable and disable functions.

Priority

All aliases/triggers are matched in priority order from highest to lowest. You can use the priority setting to control the order in which matches occur in combination with the multi setting.

RegExp

If true the pattern should contain proper regular expression syntax, if false you can use a simple * to represent a matching group.

Multi

If false then parsing stops once a match is found. If this is set to true then parsing of the alias/trigger list continues for additional matches.

Gag

If set to true the line that matched the trigger is not displayed.

Functions

You can declare functions in your scripts using the function keyword. Functions may be called from other scripts.

function simpleAddition(a, b) {
  x = a + b
  return x
}

The following built in functions may be called from within scripts.

send(text:String)

Sends text to the server.

send('look')

echo(text:String, colour:String = “#ffffff”, background:String = “transparent”)

Displays text in colour on background. The colour and background parameters are optional and can be specified as web format, eg. ‘#0000FF’.

echo('This is an echo')
echo('This is an echo in red', '#ff0000')
echo('This is an echo in black on red', '#000000', '#ff0000')

execute(text:String)

Text is parsed for an alias match before being sent to the server.

addTimer(delay:Number, code:String, repeat:int = 1)

Executes code every delay seconds, repeat times.

counter = 5
function countdown() {
  echo(counter)
  counter--
}
addTimer(1, "countdown()", 5)

enableAlias(name:String)
disableAlias(name:String)
enableAliasGroup(group:String)
disableAliasGroup(group:String)
enableTrigger(name:String)
enableTriggerGroup(group:String)
disableTrigger(name:String)
disableTriggerGroup(group:String)

These functions all work by enabling/disabling the single alias/trigger with name or all aliases/triggers that are part of group.

enableTriggerGroup("healreflexes")

Variables

The var keyword is optional and all variables are dynamically typed. Any variables declared in the top level scope of a script will be available to all other scripts.

someNumber = 5
someString = "This is a string"
someFloat = 2.6
someBool = true

The this keyword

The this keyword references an object containing details of the pattern that called the alias or trigger where this[0] is the matching substring and this[1] to this[n] are the first to nth matching groups.

Pattern: g * *
Script: send("get the " + this[1] + " from the " + this[2])

If RegExp is set to true you can use named groups in your pattern, in which case this.group_name will match the group with name group_name.

Pattern: ^(?P<hitpoints>d+)h, (?P<mana>d+)m, (?P<string>.*?)-$
RegExp: true
Script:
hitpoints = this.hitpoints
mana = this.mana
string = this.string
echo("Prompt matched!")

Finally, this.input contains the original line that matched the alias or trigger. You can use this with the gag option and an echo to colour certain lines.

Pattern: You are almost dead!
Gag: true
Script: echo(this.input, '#ff0000')

Unsupported Features

The following Javacript features are not supported:

  • try, catch, finally
  • prototype
  • with
  • include