Direction

From IFWiki

I inhale great draughts of space,
The east and the west are mine, and the north and the south are mine.

Song of the Open Road, Walt Whitman

Types of directions

Most IF authoring systems predefine twelve standard directions:

Together, the cardinal directions and the diagonal directions are called compass directions which can be displayed together as part of a compass rose.

Non-standard directions can include:

  • The four shipboard directions: fore, aft, port, and starboard.
  • The four other relative directions or facing directions: left, right, forward, and back.
  • The four disk directions or wheel directions, which have no standard names. One game call them: hubward, rimward, clockwise, and counterclockwise. Another game might name them as outward, inward, sunward, and widdershins. On a spacestation, you might use spinward and antispinward.
  • The two very rarely-used fourth dimension directions: ana and kata.

Of course, finer grades of direction like the mid-compass direction "northnortheast", the diagonal shipboard direction "fore port", or the tilted-compass direction "up north" are possible, but these are so incredibly rare as to be nearly non-existent.

Some games may have unusual directions for unusual situations. For example, to travel away from the north pole in Small World, where logically every direction is "south", you use one of eight "daytime directions" instead: morning, noon, afternoon, twilight, evening, midnight, gloaming, and dawn. That these directions are also the names of the destination rooms is probably no little coincidence.

Player usage

Players type in directions, such as NORTH or UP to move their player characters from one room to the next. These commands are usually understood to be a short form of a GO command, e.g.: GO NORTH or GO UP.

(Of course, directional commands aren't the only way for a player character to travel. Commands like ENTER TAVERN, CLIMB LADDER, RIDE HORSE, SWIM, FLY, etc. can also potentially move the PC.)

Directional commands are so common in IF that most of the standard directions have abbreviations. Those abbreviations in English are:

N is short for NORTH
S is short for SOUTH
W is short for WEST
E is short for EAST
NW is short for NORTHWEST
NE is short for NORTHEAST
SW is short for SOUTHWEST
SE is short for SOUTHEAST
U is short for UP
D is short for DOWN

Every now and then, someone new to IF will point out that using compass directions to navigate through a person's home is unnatural and breaks mimesis. (More needs to be said about this and what answer is usually given.)

Directions can also sometimes be used in a few other types of commands such as:

  • PUSH WHEELBARROW NORTH
  • LOOK WEST
  • EXAMINE SOUTH WALL
  • OPEN EAST DOOR

Coding a direction

Directions can be a bit confusing to program. In summary, we have:

  • Direction properties, e.g.: what happens if I go north?
  • Direction objects, e.g.: the concept of northness
  • Room parts, e.g.: the north wall

Direction properties

All IF authoring systems associate direction properties with rooms. That is, a room object can be expected to have a "north" property, a "west" property, and so on. The value of a room's north property would encode what happens when the PC tries to go north from that room.

Every IF system handles direction properties differently. It's a bit complicated since an author may want to specify any of the following values as succinctly as possible:

  • The destination room, or
  • The destination room (but with travel messages either on leaving the origin room or arriving at the destination room), or
  • A door (or any other object between the rooms) that effectively controls the attempted movement,
  • A travel refusal message (like: "The hedges block your path."), or
  • An arbitrary routine that may or may not move the player, perhaps deciding on one of several possible destinations, and may even have side effects such as changing the player's inventory.

NPCs can complicate matters if they have to also travel about the game map, since messages of their departures and arrivals also need to encoded as part of the direction, unless their movements can be faked some other way.

Direction objects

Confusingly, while rooms may have properties named after directions, doors may have properties whose values are directions, indicating which direction they go to. Commands like GO NORTH and PUSH BOULDER EAST also require the encoding of a directional value.

Although directional values could be encoded as an integer -- 1 meaning NORTH, 2 meaning EAST, and so on -- it has proved useful to have direction objects, the platonic notion of northness, for example.

Having directions as objects lets us give them properties of their own, such as their name so we can print it, what type of direction it is, and what its opposite direction is.

Room parts

By "room parts", we mean walls, floors, and ceilings. Most IF authoring systems do not predefine room parts, but Inform 6 and TADS 3 do.

Inform 6's standard library made the unfortunate decision to define directions as both the concept plus its associated room part. For example, the object "n_obj" represents not only the concept of northness but also the generic north wall of a room. Likewise, its down object means the idea of "down" plus the floor (or ground). This situation makes it rather difficult for Inform 6 authors to remove walls from rooms or define their own.

Fortunately, Inform 7's standard library defines directions as just the directions; room parts are not predefined in Inform 7.

TADS 3 sensibly defines room parts and directions as completely separate objects.

See also

Code Compare: Direction
Hugo:The direction class
Inform 6:The CompassDirection class
Inform 7:The direction kind
TADS 3:The Direction class