Pointers

Wherever an object or a location label can be used, so too can a number of special purpose pointers. When a command referring to a pointer is processed, the pointer will be substituted with the label of the item that it currently points to. This avoids the repetition of code and the associated problems of code-bloat and inconsistency. Below is a function demonstrating the use of pointers:

{+where_is
loop noun3
   if noun3 hasnt LOCATION
      noun4 = noun3(parent)
      write noun3{The} 
      write " is in " noun4{the} ^
   endif
endloop
}

The above function loops through all the objects defined in the game and displays their current whereabouts. The loop command sets the object pointer noun3 to each of the objects in turn, while the pointer noun4 is manually set to each object's parent.
Warning Internally, an object pointer is nothing more than an integer variable, and any integer variable, constant or element can be set to an object's label and then used anywhere an object is expected.

The two tables below detail each of the internal object and location pointers:

Object Pointers

Pointer Description
player This pointer is set to the object that currently represents the player in the game.
noun1 This pointer is set to the first object referred to in the player's last move.
noun2 This pointer is set to the second object referred to in the player's last move.
self or this This pointer is set to the object that the currently executing function is associated with.

Location Pointers

Pointer Description
here This pointer represents the location that the player is currently in. It is synonymous to the element player(parent).
destination This represents the location that the player is attempting to move into. The value of destination can be tested in the +movement function before the move is completed. Once the move is complete, destination will equal here until the next move is attempted. This is a read-only pointer and therefore cannot be used as the container parameter of a set command.
self or this This pointer is set to the location that the currently executing function is associated with.
Warning Be sure your code never makes use of a pointer in place of an object or location while it does not point to a valid object or location. A pointer is not pointing to a valid object or location if it is set to a number less than one or greater than the number of objects and locations in the game.

Back to Contents