• Tutorials

  • Home
  • GPDL Expressions



    DungeonCraft Help Home



    Like most other languages, GPDL allows you to manipulate data using expressions such as:

    HeightInInches = 12 * HeightInFeet;

    But since everything in GPDL is a string rather than a number, you will have to get used to some strange-looking expressions when you wish to manipulate numbers. The way to write the above example in GPDL would be

    HeightInInches = $TIMES(12, HeightInFeet);

    This expression is equivalent:

    HeightInInches = $TIMES("12", HeightInFeet);

    because GPDL will automatically convert '12' to a string ("12"). The reason that the expression

    HeightInInches = 12 * HeightInFeet;

    will not work is because there is no binary operator '*' for text strings. The text might represent numbers, as in

    HeightInInches = 12 * 6; // assuming HeightInFeet = "6"

    but it could also just as easily not, as in

    HeightInInches = 12 * "I'm six feet tall";

    The $TIMES operator tells the compiler that you want to convert the two text parameters into numbers and perform multiplication on them.

    There is an operator for combining strings:

    + 
    Concatenates two strings

    Second, there are operators comparing strings. All of these compare the strings as alphanumeric text. For example, "Dog" is greater than "Cat" because 'D' comes after 'C' in the alphabet. Lower-case letters come after the upper-case letters. "cat" is greater than "Dog". All these operators have as their result either true (represented by "1") or false (represented by "").

    > 
    Greater
    < 
    Less
    ==
    Equal
    >=
    Greater than or equal
    <=
    Less than or equal
    !=
    Not equal
    &&
    Both are non-empty
    ||
    At least one is non empty
    !
    Unary. Is empty.



    Third, there are operators for manipulating numbers as 32-bit integers. Each of these converts its arguments to 32-bit numbers, performs the appropriate function, and then converts the result to a string. SeeData Type Conversions





    +#
    Addition
    -#
    Subtraction
    *#
    Multiplication
    /#
    Division
    %#
    Remainder
    &#
    Bitwise AND
    |#
    Bitwise OR
    ^#
    Bitwise Exclusive OR



    Fourth, there are operators to compare 32-bit numbers.

    ==#
    Equal
    !=#
    Not equal
    <#
    Less than
    <=#
    Less than or equal
    >#
    Greater than
    >=#
    Greater than or equal



    Fifth, there are functions to operate on strings as decimal digits with infinite precision. They are not fast. But you can easily compute 1000-digit numbers if you so please.

    $EQUAL
    $LESS
    $GREATER
    $PLUS
    $MINUS
    $TIMES
    $DIV
    $MOD
    $NOT

    All of the operators have a precedence. For example, multiplications take place before additions. The normal precedence can be overridden with the use of parentheses. For example:

    x = 12 /# ( Y +# Z )

    means that 12 will be divided by the sum of Y and Z.

    Here is the normal precedence of the operators:

    Logical OR
    ||
    Logical AND
    &&
    Bitwise OR
    |#
    Bitwise XOR
    ^#
    Bitwise AND
    &#
    Equality
    ==  and ==# and != and !=#
    Comparison
    <   and <#  and > etc
    plus/minus
    +   and +# and -#
    multiply/divide
    *#  and /# and %# 



    In all cases, the operators and functions that have a true/false value as their result return a string with the single digit '1' to represent a true result and an empty string as false.

    Some more examples to illustrate how numbers and strings are manipulated:

    $RETURN "10" + "5";         // returns "105"
    $RETURN 10 + 5;             // returns "105"
    
    $RETURN 10 +# 5;            // returns "15", the '+#' means treat both params as numbers
    
    $RETURN "10" + "-5";        // returns "10-5"
    $RETURN 10 + -5;            // error, there is no unary operator '-' for strings
    $RETURN 10 - 5;             // error, there is no binary operator '-' for strings
    $RETURN 10 -# 5;            // returns "5"
    
    $RETURN $PLUS(10, 5);       // returns "15"
    $RETURN $PLUS("10", "5");   // returns "15"
    $RETURN $MINUS(10, 5);      // returns "5"
    
    $RETURN $PLUS("10", "-5");  // returns "5"
    $RETURN $PLUS(10, -5);      // error, no unary operator '-' for strings