Making "go left" correspond to the player's position [Inf 7]

Using Inform 7, how can I make it so that the player can type “go left,” “go right,” “go straight,” etc. and go in a direction corresponding to the last place he came from?

For example, let’s say the map is

x.3.x 1.2.x x.4.x

where the numbers are rooms. If the player goes from room 1 to room 2, saying “go left” should take him to room 3. Then, saying “go back” should take him to room 2. Then, saying “go straight” should take him to room 4.

Thanks for any help!

Here’s a partially coded solution (based on Ex. 102, “Polarity”) that you can flesh out.

[code]NW-Room is a room. N-Room is east of NW-Room. NE-Room is east of N-Room.

W-Room is south of NW-Room. C-Room is east of W-Room and south of N-Room. E-Room is east of C-Room and south of NE-Room.

SW-Room is south of W-Room. S-Room is east of SW-Room and south of C-Room. SE-Room is east of S-Room and south of E-Room.

The former location is a room that varies. The travel orientation is a direction that varies.

First carry out going rule:
now the former location is the location;
now the travel orientation is the noun.

Understand “go back” as retreating. Understand “back” or “return” or “retreat” as retreating.

Retreating is an action applying to nothing.

Carry out retreating:
let way be the best route from the location to the former location, using doors;
if way is a direction, try going way;
otherwise say “You can’t see an open way back.”

Going left is an action applying to nothing. Understand “go left” as going left.

Check going left:
let D be an object;
if the travel orientation is north:
now D is west;
otherwise if the travel orientation is west:
now D is south;
otherwise if the travel orientation is south:
now D is east;
otherwise if the travel orientation is east:
now D is north;
otherwise:
say “Going left doesn’t make sense right now.” instead;
try the player going D.[/code]

Thanks, Mr. Aikin. Your solution works great if working with a completely open series of rooms, but as soon as there is a doorway that the player responds to by saying “go through the doorway,” there occurs a run-time problem (P60) because it tries to make “D” into the door, which contradicts the “travel orientation is a direction that varies.”

Is there a way to make it so that when a player “goes” without choosing a direction, the program adapts as if the player had gone in that direction? Or to turn it off or ignore the rule in other cases?

Oh, dear. Unfortunately, the showme command does not reveal the direction of a door from within a room. This pretty much has to be a property of the room … but Inform is hiding it from the programmer, which is naughty. I’ll do some research on this, but maybe someone else can come up with an elegant solution before I blunder into it.

Can you use “direction of (door) from (room)”? See 3.12 in the documentation.

Thanks, Matt. This new bit of code seems to fix what I posted yesterday:

First carry out going rule: now the former location is the location; if the noun is a direction: now the travel orientation is the noun; otherwise if the noun is a door: let N be the noun; let D be the direction of N from the location; now the travel orientation is D.

Cool, Jim; glad that worked.

Lance: One thing to think about is that, if you’re going to do this, you probably want to figure out a way to generalize the directions so they can be used in contexts other than the going command. For instance, if the description of room 2 is always “There are exits to the north, south, and west” then people will be typing “n” instead of “go forward.” So you need a way to say something like “There are exits [relative-heading of north], [relative-heading of south], and [relative-heading of west],” and define a “To say relative-heading of (D - a direction)” in order to make that spit out “There are exits ahead, behind, and to the left” when the travel orientation is north, or something like that. And that means you also need to write your code so the travel orientation doesn’t get reset to “up” when the player goes up, or that room description will break. And probably you should implement “turn left” so the player can change the travel orientation without going to a new room.

All this should be doable, but seems pretty annoying. It’s worth thinking about whether this functionality is important enough for you to do all that work. It’s pretty artificial to have the protagonist be like the Kuuk-Thaayorre, always aware of the compass directions, but it does seem to help some players navigate the world.

Pacian implemented the left/right/forward/backward system very well in “Rogue of the Multiverse,” in TADS3; he might have some insight about the issues involved.

Of course what would be really great is if someone would write an extension to do this…

Yes, each room should be described differently depending on the player’s entrance. Thank you both for the help! Mr. Aikin, your fix works perfectly. I also came up with an addition:

[code]Reversing is an action applying to nothing. Understand “turn around” as reversing.

Carry out reversing:
if the travel orientation is north:
now the travel orientation is south;
say “You turn around.”;
otherwise if the travel orientation is south:
now the travel orientation is north;
say “You turn around.”;
otherwise if the travel orientation is east:
now the travel orientation is west;
say “You turn around.”;
otherwise if the travel orientation is west:
now the travel orientation is east;
say “You turn around.”;
otherwise:
say “Turning around doesn’t make sense right now.” instead.[/code]Also, Mr. W, that article about the Kuuk-Thaayorre is really interesting!

I didn’t actually map relative directions onto compass directions, though. Each room has a four-element array of exits (in clockwise order), which are assigned to forward/left/right/back depending on which one you’re coming from.

Building on compass directions probably would have been easier, but this represented how I wanted to see the layout in my own head.

This may be overkill or currently unnecessary, and it looks like the extension hasn’t been changed in a few years, but you might also be interested in Directional Facing by Tim Pittman: inform7.com/extensions/Tim%20Pit … index.html .