Regular expression tips

Posted by Kyle Hankinson August 17th, 2022


General

If you need a trigger or alias to match on a regular expression, here are some hints and tips to use.

Regex vailidation

As you type your regex, the main mud display will update to highlight matches.

  • The background will be highlighted with the full match range. The full match can be accessed in script via \0.
  • Each capture group will be underlined and can be used as a paramter in the script starting with \1, \2, \3, etc.

Whitespace

For whitespace (space, tab, linebreak) use the \s+ syntax option. While most muds will use spaces, some muds will use tabs is certain instances which may case a basic space match to fail.


Tags: Scripting

Console commands

Posted by Kyle Hankinson August 5th, 2022


Commands

#clearMessages

Clears anything currently in the messages window.

#clearOutput

Removes the main output buffer.

#autocomplete list

Displays a list of current autocomplete entries.

#autocomplete clear

Clears the autocomplete entries.

#vars

Displays a list of current script variables.

#disconnect

Disconnects from the current session. If auto-reconnect is enabled, a countdown will be started and the connection re-attempted.

#close

Disconnects the current connection and closes the window.

#set VARIABLE=VALUE

Sets the specified varaible to the specified value.

#stop

Stops any activly waiting scripts. Scripts may be in a waiting state from either a wait or a commandAndReadFromServer function.


Tags: Scripting

Functions

Posted by Kyle Hankinson August 4th, 2022


General functions

command(commandToRun)

The command function will process a command as if the user had typed it into the console. Any aliases in the command will be processed as well.

wait(timeout)

The wait function will cause the current script to delay for timeout seconds before continuing the script. The wait timeout can contain miliseconds by specifying decials.

log(logMessage)

The log function will append the specific message to the console. This can be useful when debugging scripts.

processForAutocomplete(entries)

The processForAutocomplete method adds entries to the interal autocomplete list. entries can either be an array of strings, or a string which will be delimited by whitespace.

commandAndReadFromServer(command)

The commandAndReadFromServer will process a command as if the user had typed it into the console, then will read from the server until the next data stream has finished.

beep

The beep function will cause your device to output a beep sound effect.

addComm(xxx)

Variables

Variable functions are unrelated to javascript functions. Rather they are a way to store variables over multiple scripts. Regular javascript variables are removed from memory once the funcion has completed. All varaible methods below should have variable names passed as a string.

isEmpty(variableName)

The isEmpty method returns true if a variable is unset or empty. A string variable is considered empty if it has zero length or is completely whitespace. A numeric variable is never empty (zero is not considered empty). Use the unset function to completely unset a variable.

unset(variableName)

The unset function is used to completely clear a variable.

setVar(variableName, value)

getVar(variableName)

Returns the current value of the specific variable.

macOS specfiic functions

status(display)

The status function updates the status bar to show the value for display.

notify(message)

The notify function will add a macOS notification with the specific message.

badge(display)

The badge method updates the app icon badge to show the specific display. This should be limited to a short string (less than 10 characters), or it will be truncated. Current/max HP is an example of what one might display in the badge.


Tags: General

Autocomplete

Posted by Kyle Hankinson August 3rd, 2022


What is autocomplete?

Autocomplete is a way to quickly turn a partial letter into a full word. For example if you were to type the letter look mer and hit tab, it might fill the completion text in as look merchant rather than needing to fully type out merchant.

An example:

How it works

MUD Client allows autocomplete keywords to be added via the scripting engine. An example of this could be an alias to the command look or inventory, or by a trigger that matches You see:.

To have words added to the autocomplete list, you must call the processForAutocomplete method with either an array of words or a string containing one or more words to be added. For example, you could have a login script with either of the following:

processForAutcomplete(['consider', 'kill']);
processForAutcomplete('consider kill');
A larger example based on a trigger would be as follows: In this example a regular expression is used to match from `You see:` until > (the cursor input for this mud). Everything inbetween is added for autocomplete.
Tags: General Scripting

More articles: