|
|
|
An Alias is a shortcut name that contains a list of commands to be executed. In terms of other programming languages, an Alias is like a Procedure or Method call. When the Alias name is entered on the command line, any script assigned to the Alias is executed. For example:
#ALIAS eb {eat bread}
This defines an Alias named "eb". When you type "eb" on the command line and press Enter, the script assigned to the Alias is executed. In this case, "eat bread" is sent to the MUD.
As shown above, you can create an Alias on the command line using the #ALIAS command. You can also create an alias withing the Package Editor Aliases screen.
Arguments
You can pass command line arguments to an alias. This is similar to command line arguments passed to commands on the Unix or DOS command lines. Just separate each argument with a space. For example:
eb bread butter
would pass "bread" as the first argument, and "butter" as the second argument on the command line.
To access the arguments within the script, use the %1..%99 syntax, where %1 is the first argument, %2 is the second argument, and so on. For example:
#ALIAS k {kill %1}
defines an Alias named "k" with a script that sends "kill" followed by the first argument to the MUD. So if you type:
k rabbit
on the command line, then "kill rabbit" is sent to the MUD. Instead of trying to remember which number the argument is, you can also use "Named Arguments". To use a named argument, you must declare the argument list just after the name of the alias using the following syntax:
#ALIAS name($arg1,$arg2,...) {script}
Each named argument must start with a $ character (because a Named Argument actually creates a Local Variable). Each argument must be separated by a comma and the list is enclosed in () parenthesis.
NOTE: There must NOT be any space between the alias name and the ( parenthesis that begins the argument list.
So, the above example would now look like this:
#ALIAS k($target) {kill $target}
That's a bit more typing for this simple example, but using Named arguments can make your scripts much easier to read when they are more complicated.
Sometimes you might want to access all of the arguments at once. The special syntax %-1..%-99 is used for this. %-1 expands to all arguments from the first to the last. %-2 expands to all arguments from the second to the last.
For example, if you typed "myalias this is a test" where "myalias" is the name of your alias, then %1 = "this" but %-1 = "this is a test". %2 = "is" and %-2 = "is a test", and so on.
When using Named arguments, you can use the %param and %params functions to access the arguments. %param($arg1) is the same as $arg1 or %1. %params($arg1) is the same as %-1. %numparam can be used to return the number of arguments that were passed to the alias. |
|