Advanced Programming

In the section on variables and triggers you learned the basics about programming in zMUD. However, zMUD is a powerful event-driven programming language, and you have barely touched the surface of what is possible. In this section, a more detailed explanation of command parsing will be presented, and functions will be introduced. If you fully understand how zMUD parses its commands, you will find that zMUD is capable of doing most anything you desire.

Command Syntax and Parsing

Every time you enter a command and press Enter, the command text is parsed. This parsing several steps:
break the input using the separator character (;) into individual commands
determine the focus of the command
execute the command

When commands are executed, the type of each parameter determines whether the parameter will be expanded, evaluation, or left alone. For nitty-gritty details of the zMUD Programming syntax, read the zMUD Programming Language Manual on the web at

For example, the #VAR command takes a String parameter, which is expanded, so

#VAR temp 5      assigns the number 5 to the variable temp
#VAR hp {100/@temp}
#SHOW @hp      displays 100/5

However, the #MATH command takes an Expression which is evaluated, so

#VAR temp 5      assigns the number 5 to the variable temp
#MATH hp 100/@temp
#SHOW @hp      displays 20

The #FUNC command takes a Literal which is left alone, so

#VAR temp 5      assigns the number 5 to the variable temp
#FUNC hp 100/@temp
#SHOW @hp      displays 100/@temp

One final word about parsing and variable expansion. Normally, each variable must be separated by spaces to allow proper parsing. Thus, if the variable @a has the value test, you must normally say @a ing to get @a to expand. If you say @aing zMUD looks for a variable called aing. You can use the curly braces {} to surround the name of the variable to solve this problem. Thus, @{a}ing expands to testing.

You can use the above syntax to perform indirect variable addressing. Letís say that the variable @b has the value a. Referring to @{@b} expands the value of @b, resulting in @{a} which expands to test.

If you ever want to use one of the special zMUD characters like @ or %, you can use the tilde character (~) to "quote" the special character. Thus, would tell zMUD not to interpret @ as a variable character. To actually use a tilde character, use two of them.


In addition to variables, zMUD allows you to define functions. Think of functions as variables with parameters. Parameters are used much like they are with aliases, except that since they are expanded within a command string, the syntax for calling a function is a bit different.

You declare functions just like variables, using the #VARIABLE command. However, in the definition of the function, you can use %1, %2, etc to refer to parameters to be supplied by the caller. For example, #VARIABLE kk {kill %1;stun %1} defines a function called @kk that takes one parameter. You expand and execute this function by using the @ character in front of the function name, then put the required parameters in parenthesis (much like in a programming language). Thus @kk(zombie) will expand to kill zombie;stun zombie. Recall that this is similar to the kk alias that we defined in the Introduction to Aliases section, but unlike aliases, functions are expanded during the parsing phase anywhere in the command, rather than performed at the execution phase.

To add more power to zMUD, several predefined functions are supplied. They provide the tools necessary for some very powerful trigger processing. By using the predefined functions in combinations with your own functions, the sky is the limit!

Contents Advanced Editing Function Reference