Home mm2k6 Help Files Commands Script Flow Control - IF command
21 | 04 | 2018
Script Flow Control - IF command
Article Index
Script Flow Control
IF command
All Pages


Format: /if {conditional statement} {then} {else}

If commands need to be activated in some fashion in order to be evaluated. Most commonly you would place an if command inside an action. However, they could also be place inside an alias or macro. The if command has been modeled after an if statement in C.

Note: within if conditions string variables are automatically surrounded by double quotes but numeric variables are not. Both sides of every condition MUST be quoted or not quoted. When one side is quoted and the other not then the condition causes an error and the if evaluates to false.

  • {conditional statement} This is a statement that evaluates to either true for false. Any statement evaluating to a 0 is considered false, while any other result would be considered true. 
  • {then} The commands you place here will be executed if the condition is evaluated to true. {else} The commands you place here will be executed if the condition is evaluated to false. This paramater is optional.

Operators recognized by if:

 Operator Description Operator Description
&&AND ||OR 
!= Not equal to  Greater than
== Equal to Equal to 
 Less than>= 

Greater than or equal to 

<=Less than or equal to ( ) Precedence 

Operators are evaluated in this order: (), &&, ||, =, ==, !=, >, <, >=, <=.

Conditional statements or parts of conditional statements can be negated with ! as long as the portion of the statement being negated is surrounded by parentheses.

To use !, it would be something like

/if {!($0 > 5)} {/showme {$0 is smaller}} {/showme {$0 is larger}}

/action {^You are hungry.} {/if {$AutoEat = 1} {take food bag;eat food}}

The above would allow you to turn eating on and off. You need to define a
variable called AutoEat and give it a value of 1 when you want eating to be
automatic, and any other number when you want to turn it off.

/action {%0 enters the room.} {/if {$MeanMode = 1 && ($0 = "Atlas" || $0 = "Breedan")} {spit $0}}

Assuming the mud sent the text "<character name> enters the room." each time
somebody entered the room. Each time somebody enters the room the client would
check to see if MeanMode is 1, and that the name of the person who entered is
either Atlas or Breedan, and if it is, would spit on them.