• Tutorials

  • Home
  • GPDL $IF Keyword

    DungeonCraft Help Home

    The $IF keyword is used to execute code conditionally. It may be combined with the $ELSE keyword to execute one of two alternative sections of code. Syntax is:

      $IF ( exp ) { stmts1 } [$ELSE { stmts2}];

    The square brackets around the second part indicate that the brackets and what is between the brackets is optional.

    When the program runs, exp is evaluated. If it is true then statements 'stmts1' are executed. If exp is false the statements 'stmts2' are executed. Examples:

    Example 1:

      $IF ( IsHolding ("PotionOfDistortion"))
      {
        Distort(3);
      };



    Example 2:

      $IF ( $nEqual ( x, 1))
      {
        $RETURN "Now";  // x==1
      }
      $ELSE
      {
        $RETURN "Later"; // x != 1
      };