Expressions

[Command Reference] [Function Reference] [Predefined Variables] [Expressions]

zMUD implements full expressions. Expressions can contain variables, and most common operators. Parenthesis can be used to override default operator precedence. When evaluating an operation, if all parameters of the operation are numeric, then a numeric operation is used, otherwise a string operation is used. The following operators are recognized (v1 and v2 represent variables, or other expressions). The list is in precedence order, with the highest precedence operators at the top.

 
!v1      return the logical NOT of value1
not v1      same as above
-v1      return the negative of value1
v1 * v2      multiply value1 by value2
v1 / v2      divide v1 by v2. Any fraction is discarded.
v1 \ v2      divide v1 by v2 and return the modulo
v1 + v2      add value1 to value2. If values are not numeric, the text values are concatenated.
v1 - v2      subtract value2 from value1
v1 = v2      true if value1 is the same as value2
v1 > v2      true if value1 is greater than value2
v1 < v2      true if value1 is less than value2
v1 >= v2      true if value1 is greater than or equal to value2
v1 <= v2      true if value1 is less than or equal to value2
v1 <> v2      true if value1 is not equal to value2
v1 != v2      true if value1 is not equal to value2
v1 =~ v2      true if the string v1 matches the pattern in v2
v1 & v2      returns the logical AND of value1 and value2
v1 and v2      same as above
v1 | v2      returns the logical OR of value1 and value2
v1 or v2      same as above
v1 xor v2      returns the logical XOR of value1 and value2

If the pattern matching=~ operator is used, any saved pattern parameters are available in the true-command or false-command if expression is part of an IF command. However, you must use %% in front of the pattern to access the trigger pattern match variable rather than the alias parameters.

The constants: true, yes, on are defined with a value of 1, and the constants: false, no, off are defined with a value of 0.

Keep in mind that the AND, OR, XOR, and NOT operators are logical operators and not bitwise operation. For bitwise operations, use the various bitwise functions in zMUD. For example: (2 AND 4) is true using the logical operation, but %bitand(2,4) returns zero, which is false!



Contents