The Set Command

Any set command must be of the following format:

   set container operator value

The set command enables you to modify the current value of the specified container. A container is either an item element (see Definitions in Detail for more information), a variable or an item pointer such as noun1 or here. See the Glossary for a detailed description of the possibilities for value.

The following is a list of operators that can be used with the set command:
Operator Description
=

Make the given container equal to the given value.

+

Add the given value to the given container.

-

Subtract the given value from the given container.

/

Divide the given container by the given value.

*

Multiply the given container by the given value.

Mathematical Functions

Like many other JACL commands, the set command accepts only a static number of parameters. For this reason, complex expressions must be evaluated using several steps.

For example, to add 7 and 9 then divide the result by 4, you must create a variable, then use the following code:


   variable TEMP

   {+maths
   set TEMP = 7 ;Sets the current value of TEMP to 7
   set TEMP + 9 ;Adds 9 to the current value of TEMP
   set TEMP / 4 ;Divides the current value of TEMP by 4
   }
Although all JACL commands require a space between each parameter, it is especially easy to forget the space between the container and the operator or the operator and the value. It is, of course, valid to have a command such as:
   set BANK_BALANCE = -42

Type Casting

Rigid type enforcement is considered a highly-desirable strength in a modern programming language. I consider it a pain in the arse. All the possible expressions that can be given for value in a set statement resolve to a single integer. Due to this fact, there are no real issues with type casting in JACL, and all of following commands are perfectly valid:


   set VARIABLE = small_frog
   set noun4 = VARIABLE
   set noun4 + 1 ; NOTE: noun4 will now equal the item defined
                 ; directly after small_frog in the game file.
   set lantern(status) = noun1(parent)
   set sword(parent) = random
The only real potential danger in the above examples it that of setting one of the object pointers to a value less than one, or greater than the internal number of the last object.