[Home] [Downloads] [Search] [Help/forum]

MUSHclient complex alias script

MUSHclient logo - 15K

Updated 15th June 1997.


This example script assumes you have read the companion article: Scripting a simple alias

The main drawback with the simple example is that you have to amend the script every time you want to add a new location to teleport to.

This example shows how to store teleport locations as a MUSHclient "variable", so that you can add new locations "on-the-fly". As the variables are stored in the world file they are saved when you save the world, and available next time you use that world.

Typing in the script subroutine

Use Notepad (or some other text editor) to edit the script file (the file whose name appears on the "scripts" configuration page) and add the following subroutine (you can copy from this web page and paste into the file). Both subroutines below are supplied in the file "exampscript.vbs" which accompanies MUSHclient.

Interestingly, although this version is much more flexible, it is only about 10 lines longer than the simple version. What is happening is:
  1. The third parameter passed into the script subroutine (called "thewildcards" here, but you could call it anything) is the array of wildcards to the alias, in other words "whatever the user typed after the word TELEPORT".
  2. This first wildcard ("thewildcards (1)") is "trimmed" by using the "Trim" function. This removes leading and trailing spaces, and moved into the variable "sDestination" in the process.
  3. If the destination is blank (ie. the user typed nothing in) then the program echoes the possible teleport locations, and exits the subroutine. It does this by:
  4. Otherwise, using "world.getvariable" the contents of the appropriate variable is fetched
  5. If there is no match, a warning message is displayed (using world.note) and the subroutine exits.
  6. If there is a match, the subroutine displays an informative message, and then sends the appropriate teleport command to the world.

Linking the alias to the script

The only thing that remains is to add an alias called "teleport" (you could make it "tel" if you want to save some typing), and tell it to call the script subroutine "OnTeleport" (ie. the one you just created) if someone types "teleport".

The resulting alias will look like this:

Example of alias - 5K

Making another alias to add rooms to the list

The next trick is to add rooms to our list of rooms that we can teleport to. To do this, I have defined another VBscript subroutine "OnAddTeleport" which is called from an alias "add_teleport". This subroutine expects you to type in a room name followed by its number, like this: The subroutine uses two wildcards to allow you to type in two words separated by a space. It does a couple of checks (eg. that the second word is a number) and then calls "world.setvariable" to add it to the variables list. The subroutine looks like this:

Add the second alias

You will now need to add an alias which matches on "add_teleport" with a script subroutine of "OnAddTeleport", using a very similar method to the one for adding the "teleport" alias.

In this case, however, you need to match on:

add_teleport * *

The first wildcard is the room name, the second wildcard is the room number.

Test it out!

Having typed in the script, and set up both aliases, you are ready to try them!

First type in:

And then type in: Here is what it looked like for me...

Alias example - 5K

If you get syntax errors, just edit the script file and correct them. If you are using Window NT, MUSHclient will automatically detect that you have changed the script file and offer to reprocess it. If you are using Windows 95, just use the "reload script file" function (Shift+Ctrl+R).

Once you have added a couple of teleport destinations you can look at them in the variables configuration screen. You can also use that screen to change or delete destinations. Here is an example:

Variables example - 4K

[Previous] [Back] [Home]
Written by Nick Gammon - 5K

Comments to Gammon Software support

[Best viewed with any browser - 2K]    Internet Contents Rating Association (ICRA) - 2K    [Web site powered by FutureQuest.Net]

Page updated on Tuesday, 6 December 2005