if

Arguments:
(1)boolean, any, any
(1)boolean, any
Return Value:
any

The if statement isn't actually a function, although it looks like one. The difference is that functions always evaluate ("run") all of their arguments before being called, while the if statement conditionally evaluates only zero or one of its arguments after the first argument.

The if statement checks if a condition is true, and then executes one set of code if it is, another if it isn't. The usage is

   if ( condition, code if true, code if false )
or
   if ( condition, code if true )

in which case it does nothing if the condition is false. The condition can evaluate to anything, not just a boolean. If the condition evaluates to something other than a boolean, then it's considered true if it isn't null and false if it is null.

The if statement evaluates to the result of the executed code. If the second form is use and the condition is false or null, then the if statement evaluates to null, and that null has the same type as the code-if-true block.

Examples:
   if ( hp(%a) + 10 < maxhp(%a),
      set( hp(%a), hp(%a) + 10 ),
      set( hp(%a), maxhp(%a) ) )

heals %a (the person who issued whatever command triggered this MUDL script) by 10 hit points unless that would go over his max hp, it which case it just heals him up to max hp. The condition in this case is

   hp(%a) + 10 < maxhp(%a)
the code if true is
   set( hp(%a), hp(%a) + 10 )
and the code if false is
   set( hp(%a), maxhp(%a) )

Say we also want to give the person a message if ANY healing is done. That makes a three-way condition (hp <= maxhp - 10, or hp between maxhp - 10 and maxhp - 1, or hp >= maxhp in which case we don't want any message). Then we can use nested if statements as follows:

   if ( hp(%a) + 10 < maxhp(%a),
      ( set( hp(%a), hp(%a) + 10 ),
        msg_character( %a, 'You are healed!' ) ),
      if ( hp(%a) < maxhp(%a),
         ( set( hp(%a), maxhp(%a) ),
           msg_character( %a, 'You are healed a little bit.' ) ),
         msg_character( %a, 'You already feel fine.' )
      )
   )
Here we use parentheses to create lists of commands that get executed sequentially. The condition is still
   hp(%a) + 10 < maxhp(%a)
the code if true is
   ( set( hp(%a), hp(%a) + 10 ),
     msg_character( %a, 'You are healed!' ) )
and the code if false is a second if statement,
   if ( hp(%a) < maxhp(%a),
      ( set( hp(%a), maxhp(%a) ),
        msg_character( %a, 'You are healed a little bit.' ) ),
      msg_character( %a, 'You already feel fine.' )
   )
In this second nested if statement, the condition is
   hp(%a) < maxhp(%a)
the code if true is
   ( set( hp(%a), maxhp(%a) ),
     msg_character( %a, 'You are healed a little bit.' ) ),
and the code if false is
   msg_character( %a, 'You already feel fine.' )