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
set 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.
 |
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:
| 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. |
| noun3 |
A general-purpose object pointer not bound to the player's move. The standard library uses it as the iteration variable inside loop blocks, and it also receives the first argument passed to a function (see the Passing Arguments section) for historical reasons. The example at the top of this chapter sets it implicitly via loop. |
| noun4 |
A second general-purpose object pointer. By convention noun4 is used for scratch work that needs to outlive a single statement (the example above uses it to hold each object's parent during a loop). |
| self or this |
This pointer is set to the object that the currently executing function is associated with. |
| Pointer |
Description |
| here |
This pointer represents the location that the player is currently in. It is synonymous with 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. |
| limbo |
A sink location for objects that are out of play. When an object is dropped in a location with ON_WATER, MID_WATER, MID_AIR, or TIGHT_ROPE, the standard library moves the object to limbo rather than leaving it on the floor. Items in limbo are not visible or reachable by the player; setting an object's parent to limbo is the canonical way to take it out of play without destroying it. |
 |
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