Compass and nautical directions

I can’t replicate the system for switching between compass and nautical directions from 3.26. The syntax given for mapping the one onto the other is:

Index map with fore mapped as north. Index map with aft mapped as south. Index map with port mapped as west. Index map with starboard mapped as east.

But that doesn’t work for me. At least, it doesn’t work if you try to map the compass directions onto the nautical directions, which are the ones my game is written in. (It compiles, but the compass directions always result in going nowhere.) I don’t suppose there’s a way to make this work, short of rewriting my game in compass directions?

The bit of code you quote is a hint for the index maker: it tells Inform to map those nautical directions as though they were NSEW directions it already knows about. It doesn’t do anything about making nautical directions and compass directions identical for the player.

There would be a couple of ways to make compass directions match up with the nautical directions, but the one that’s probably easiest to fit to an existing game written with nautical directions would be just to redirect the compass commands into nautical ones.

Instead rules would probably work for this, but I myself would write

Setting action variables for an actor going north: change the noun to fore. Setting action variables for an actor going south: change the noun to aft. Setting action variables for an actor going west: change the noun to port. Setting action variables for an actor going east: change the noun to starboard.

…because this is general enough to work even when other characters than the player are moving around, and it’s unlikely to conflict with any instead rules you have already going in the game.

The major problem there is that it apparently executes before “before” and “instead” rules, preventing me from ever writing compass-specific or nautical-specific rules.

You can apply conditions to the setting action variables rules as well, e.g.:

Setting action variables for an actor going north when the player is in the ship: change the noun to fore.

–Erik

Yes, I’ve got that, but that’s insufficient because it still treats “fore” and “north” as functionally identical within the context. That is, I don’t think there’s any way to write a rule that applies if you go fore on the ship, but not if you go north (or vice versa).

Okay, I think I misunderstood what you wanted. What’s the intended behavior?

I want to be able to toggle them so that only one type of directions is active at a time. With the above syntax, there seems to be no way to prevent you from using nautical directions when compass directions are active.

Here’s one way to do it using Emily’s syntax:

[code]A direction can be compass, nautical, or positional (this is its category property). A direction is usually compass.

A direction has a direction called the counterpart.

Fore is a direction. The opposite is aft. The counterpart is north.
Aft is a direction. The opposite is fore. The counterpart is south.
Port is a direction. The opposite is starboard. The counterpart is west.
Starboard is a direction. The opposite is port. The counterpart is east.

Fore, aft, port, and starboard are nautical.

Up is positional. [A bug in Inform prevents assigning all four at once.]
Down is positional.
Inside is positional.
Outside is positional.

Compass mode is a truth state variable. Compass mode is false.

Setting action variables for an actor going a compass direction when compass mode is true:
change the noun to the counterpart of the noun.

Setting action variables for the player going a compass direction when compass mode is false:
change the noun to nothing.

Instead of going when the noun is nothing and compass mode is false:
say “You’re shipboard now, lubber. You’ll use fore, aft, port, and starboard or you’ll walk the plank.”[/code]

You’d also want to add some rules for the opposite situation; i.e., when the player types a nautical direction while compass mode is true.

–Erik

With that code, there still doesn’t seem to be any way to write a rule preventing you from using nautical directions when the mode is set to compass. You can’t just do the same thing in reverse because the “instead” statement will trigger for both sets of directions when it’s in compass mode.

Sure you can:

Instead of going nothing when compass mode is true: say "You're on land now, friend, so that direction doesn't make any sense. Use compass directions."

That said, I had some of the original logic backward (should have tested it!) Here’s (what seems to be) a fully working version:

[code]A direction can be compass, nautical, or positional (this is its category property). A direction is usually compass.

A direction has a direction called the counterpart.

Fore is a direction. The opposite is aft.
Aft is a direction. The opposite is fore.
Port is a direction. The opposite is starboard.
Starboard is a direction. The opposite is port.

Fore, aft, port, and starboard are nautical.

The counterpart of north is fore.
The counterpart of south is aft.
The counterpart of east is starboard.
The counterpart of west is port.

Up is positional. [A bug in Inform prevents assigning all four at once.]
Down is positional.
Inside is positional.
Outside is positional.

Compass mode is a truth state variable. Compass mode is false.

Setting action variables for an actor going a compass direction when compass mode is true:
change the noun to the counterpart of the noun.

Setting action variables for the player going a nautical direction when compass mode is true:
change the noun to nothing.

Instead of going a compass direction when compass mode is false:
say “You’re shipboard now, lubber. You’ll use fore, aft, port, and starboard or you’ll walk the plank.”

Instead of going nothing when compass mode is true:
say “You’re on land now, friend, so that direction doesn’t make any sense. Use compass directions.”[/code]

–Erik

This is strange. My code is almost identical to yours, but it won’t let you use either type of directions on compass mode.

[code]Navigation type is some text that varies. Navigation Type is “nautical”.

A direction can be nautical, compass, or universal. A direction is usually universal. Port, starboard, fore, and aft are nautical. North, south, east, west, northwest, southwest, northeast, and southeast are compass.

Switching navigation is an action applying to nothing.
Understand “switch navigation” or “switch navigation type” or “change navigation” or “change navigation type” as switching navigation.
Carry out switching navigation:
if navigation type is “nautical”:
now navigation type is “compass”;
otherwise:
now navigation type is “nautical”.
Report switching navigation:
say “[italic type]You are now using [navigation type] directions.[roman type][paragraph break]”

Instead of going when the noun is nothing and the navigation type is “compass”:
say “[italic type]You are using compass directions. Type ‘switch navigation’ to switch to nautical directions.[roman type][paragraph break]”.

Instead of going a compass direction when the navigation type is “nautical”:
say “[italic type]You are using nautical directions. Type ‘switch navigation’ to switch to compass directions.[stopping][roman type][paragraph break]”.

The starboard is a direction. The starboard has opposite port. Understand “s” or “sb” or “st” as starboard.
The port is a direction. The port has opposite starboard. Understand “p” as port.
The fore is a direction. The fore has opposite aft. Understand “f” or “front” or “forward” or “forwards” as fore.
The aft is a direction. The aft has opposite fore. Understand “a” or “backward” or “backwards” as aft.

Setting action variables for an actor going a nautical direction when the navigation type is “compass”:
change the noun to nothing.

Setting action variables for an actor going north when navigation type is “compass”:
change the noun to fore.
Setting action variables for an actor going south when navigation type is “compass”:
change the noun to aft.
Setting action variables for an actor going west when navigation type is “compass”:
change the noun to port.
Setting action variables for an actor going east when navigation type is “compass”:
change the noun to starboard.[/code]

The problem is the placement of this sentence:

Port, starboard, fore, and aft are nautical.

Your code will work if you place it after the declaration of the shipboard directions. It seems that, when placed before the declarative sentences, this line actually creates the directions, and your later “The port is a direction” statements are either ignored or serve to create another direction (with the same name?) I don’t have much time to spend looking into this right now, but maybe someone else does. Anyway, the syntax around creating directions seems to have a lot of bugs swirling around it…

–Erik

Ahhh. Thank you very much!

Wait. No. That still doesn’t work. Try it; if you switch to compass mode, it won’t let you use either set of directions.

Your rules work, though. So there is still something different between them.

Ah, sorry. I should have kept looking after seeing that. Your use of particular direction names in the setting action variables rules (rather than an adjectival description as I used) gives those rules priority over the rule that sets the noun to nothing. Make the latter a “first” rule instead:

First setting action variables for an actor going a nautical direction when the navigation type is “compass”:

That should do it. Also, note that your “s” abbreviation for starboard will raise a disambiguation error (with the “s” in south) unless you wrap in a conditional understand statement.

–Erik

Great, there we go. That’s what it looked like was happening: The “setting action variables” rules were first changing the compass directions to nautical directions, and then changing the nautical directions to nothing.

I’ve got “does the player mean” statements disambiguating south and starboard.