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

Commands that allow you to control the flow of script execution are

  • /if
  • /loop
  • /while


Format: /while {condition} {commands}

While executes the command as long as the condition is true.

  • {condition} A condition that evaluates to true or false. See help on if  for information on the condition.
  • {commands} The commands will be executed until the condition is false.

Caution is advised when using the while command. It creates a loops that does
not stop until the condition is evaluated as false. If you create a condition
that never evaluates to false it will stay in an infinite loop. An example of
an infinite loop is this: /while {1 = 1} {say doh!} This while will never stop
executing and the program will appear locked up. The idea behind the while is
to create a condition that uses variables. Somewhere in the commands portion
you would set a variable causing the loop to fail.


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.



Format: /loop {start,end} {commands}

Loop increments or decrements a number from start to end. Each time the number
is incremented or decremented the commands are executed. The loop number is
placed in the system variable $LoopCount.

  • {start,end} The start and ending numbers for the loop. If start is bigger than end, the loop will count backwards.
  • {commands} The commands to execute for each count of the loop.

/loop {1,3} {examine $LoopCount.corpse}
This would send the text "examine 1.corpse" "examine 2.corpse" and "examine 3.corpse" to the mud.

/loop {3,1} {look $LoopCount.man}
This does exactly the opposite. The number is decremented rather than
incremented and would send the text: "look 3.man" "look 2.man" "look 1.man"