Command Reference used in Dunjon 2

DEF FN

TYPE: Statement
FORMAT: DEF FN variable(parameter) = formula

This command allows you to define a complex calculation as a function with a short name. In the case of a long formula that is used many times within the program, this can save time and space. One parameter variable is used in this definition, but the formula may use any variable to calculate its result, and does not have to use the parameter variable.

This function name will be FN and any legal variable name (1 or 2 characters long) and is followed by the parameter in parenthesis. This parameter will be substituted into the formula wherever the parameter variable is located.

  10 DEF FN A(X) = 2 * ( 6 - X / 3 )
  20 PRINT FN A(12)          ^
                ^            |
                |            | 12 is inserted where
                +------------+ X is in the formula

When RUN, this program displays "4" as the answer. The result of the formula is calculated every time the FN statement is used, using the value given in the parentheses.


RND (random number)

TYPE: Function-Numeric
FORMAT: RND(numeric)

RND returns a random number in the range 0-1. The numeric parameter can have three functions. If a negative value is used, it will reseed the generator. The use of the same negative number will result in the same sequence of "random" numbers. If zero is used, the result will be the same random number as the last one. Any positive number will generate the next "random" number. To generate different random numbers every time, seed the random number generator with RND(-TI) first.

The formula for generating a number between 0 and X is:

  N = RND(1) * X
To generate a number between X and Y, use

  N = RND(1) * (Y - X) + X