Title Case for Headings by Nathanael Nerode


Section 1 - The Problem

It is traditional to give rooms titlecased names, like "The Meadow". However, it is also often desirable to put a room into scope. This may be done so that people can say "look at the meadow", or so that people can look at faraway rooms. When the room is in scope, or for other reasons, the room name may be printed in various other contexts, including some of the responses in the Standard Rules. And often we don't want those to be titlecase.

For instance, if you try this, the title in the status line and room description heading will be "Meadow"; but 'take meadow' will print "You would have to get out of the Meadow first."

"Too Much Uppercase"

The Meadow is a room. "This is a meadow."

After deciding the scope of an object (called character):
     Place the location of the character in scope, but not its contents.

And if you try this, 'take meadow' will print "You would have to get out of the meadow first", but the title in the status line and room description heading will be "meadow".

"too much lowercase"

a meadow is a room. "This is a meadow."

After deciding the scope of an object (called character):
     Place the location of the character in scope, but not its contents.

test case with "take meadow / look"

When you start having rooms with possessive names like "John's Hotel Room", it gets even more complicated. You probably want it to be called "the hotel room" in text but "John's Hotel Room" in the status line and headings.

Section 2 - The Solution

This extension will convert names like "babbling brook" to "Babbling Brook" (or "box" to "Box", etc.) for the heading at the top of the room description, and for the status line, but otherwise keep them in lowercase. So we will see:

Babbling Brook
This is a location.
> take brook
You would have to get out of the babbling brook first.

The example Meadow does this.

In addition, if a room or other object has the property "title", that will be used for the headings instead. The type "titled room" is provided as a kind of room with a "title" property, but you can also give other kinds a "title" property if you want to.

The examples The Meadow and Near the Pond do this.

Section 3 - Advanced Solution - the printing a heading activity

This extension also introduces the "printing a heading" activity.

Printing a heading is active when printing the room name at the top of a room description. It is not active when printing the name of a dark room, which has its own "printing the name of a dark room" activity.

Printing a heading is also active when printing the name of a thing at the top of the visibility threshold. For instance, if you're inside a closed opaque box, the heading should read:

Box But it is not active when printing the name of a container which is not at the top level, so that you will get:
Green Room (in the box)

Printing a heading is also active when printing a name for the status line. (This does not normally have parenthetical expressions on it so I did not special-case them.)

By default, printing a heading will apply title case to the printed name of the object (See "Meadow".) If the object has a "title" property, it will instead print that. (See "The Meadow" and "Near the Pond".) But it can be overridden to print whatever you want.

The example "People's Rooms" implements a complex naming scheme involving possessives, which change depending on who the player character is.

Section 4 - Making it work right with "Undo" - Include Undo Output Control

There is one annoying corner case. When "undo" is successfully executed, the room name is printed as a heading. For this extension to process this heading correctly, it is necessary to:

Include Undo Output Control by Erik Temple.

The newest version of Undo Output Control is on the "Friends of I7" extension page on Github. I updated it specifically so that I could fix this bug. If you have trouble including Undo Output Control, you may just be willing to live with the bug.

Example: * Meadow - The title is Meadow, the name is meadow

The title in the status line and room description will be "Meadow". 'take meadow' will print "You would have to get out of the meadow first."

"Meadow"

Include Undo Output Control by Erik Temple.
Include Title Case for Headings by Nathanael Nerode.

A meadow is a room. "This is a meadow."

After deciding the scope of an object (called character):
Place the location of the character in scope, but not its contents.

test case with "take meadow / look / undo"

Example: * The Meadow - But we want the title to be *The* Meadow.

The title in the status line and room description will be "The Meadow". 'take meadow' will still print "You would have to get out of the meadow first."

"The Meadow"

Include Undo Output Control by Erik Temple.
Include Title Case for Headings by Nathanael Nerode.

A meadow is a titled room. "This is a meadow."
The title of the meadow is "The Meadow".

After deciding the scope of an object (called character):
     Place the location of the character in scope, but not its contents.

test case with "take meadow / look / undo"

Example: ** Around the Pond - A more complex example

Pond rooms will have titles like "South of the Pond", which confuses Inform 7. We have four rooms which should be called the same name when printed in ordinary sentences, which also confuses Inform 7. Accordingly they're privately-named and we handle names manually.

"Around the Pond" by Nathanael Nerode

Include Undo Output Control by Erik Temple.
Include Title Case for Headings by Nathanael Nerode.

After deciding the scope of an object (called character):
     Place the location of the character in scope, but not its contents.

A pond room is a kind of room.
A pond room is always privately-named.
A pond room is always improper-named.
The printed name of a pond room is usually "grassy verge".

A pond room has some text called title.

Pond-Center is a pond room.
The printed name of Pond-Center is "pond".
The title of Pond-Center is "The Pond".
The description of Pond-Center is "The pond is still and calm.".
Understand "pond" as Pond-Center.
Instead of going to Pond-Center, say "[We]['re] not dressed for swimming."

After deciding the scope of an object (called character):
if the location of the character is a pond room:
     Place Pond-Center in scope, but not its contents.

Pond-N, Pond-S, Pond-E, and Pond-W are pond rooms.
The title of Pond-N is "North of the Pond".
The title of Pond-S is "South of the Pond".
The title of Pond-E is "East of the Pond".
The title of Pond-W is "West of the Pond".

The description of Pond-N is "This is the grassy verge north of the pond."
The description of Pond-S is "This is the grassy verge south of the pond."
The description of Pond-E is "This is the grassy verge east of the pond."
The description of Pond-W is "This is the grassy verge west of the pond."

Understand "verge", "grassy verge", "grassy", and "grass" as Pond-N.
Understand "verge", "grassy verge", "grassy", and "grass" as Pond-S.
Understand "verge", "grassy verge", "grassy", and "grass" as Pond-E.
Understand "verge", "grassy verge", "grassy", and "grass" as Pond-W.

Pond-N is northeast of Pond-W.
Pond-S is southeast of Pond-W.
Pond-N is northwest of Pond-E.
Pond-S is southwest of Pond-E.

Pond-N is north of the Pond-Center.
Pond-S is south of the Pond-Center.
Pond-E is east of the Pond-Center.
Pond-W is west of the Pond-Center.

The player is in Pond-N.

test descriptions with "x verge / x pond / take grass / take pond"

Example: **** People's Rooms - Rooms with possessive names

This example lets you play the game as John or Alice, using an initial Pick Identity scene. After picking an identity at the start of the game, the default "yourself" object is removed. The text substitutions adjust the printed names and titles of the dorm rooms to match (so one of them is "Your Dorm Room" and the other is "Alice's Dorm Room" or "John's Dorm Room".

There is one really tricky bit. The Standard Rules will not list an item in the room description if it believes the item has been mentioned already. Using the possessive form of John in the title of the room causes it to be marked as mentioned, so it must be unmentioned before the room description is printed -- or else John will turn invisible when in his own room.

In the Pick Identity scene, it is necessary to run the scene checking rules manually to trigger the scene change at the right time. The initial room description must be deferred until after the identity is chosen, as well.

Note the careful attention to capitalization in the descriptions. The title case in the headings, however, happens automatically.

Test this by looking at all the rooms as John, and then by looking at all the rooms as Alice.

"People's Rooms" by Nathanael Nerode

Include Undo Output Control by Erik Temple.
Include Title Case for Headings by Nathanael Nerode.

To say unmention (item - a thing):
     now item is not mentioned;

Pick Identity is a scene.
Pick Identity begins when play begins.
Pick Identity ends when the player is not yourself.

When Pick Identity begins:
     now the command prompt is "Would you like to play as John or Alice? >".

The initial room description rule is not listed in the startup rulebook.

After reading a command when Pick Identity is happening:
     if the player's command matches "Alice":
         now the player is Alice;
         follow the scene changing rules;
     otherwise if the player's command matches "John":
         now the player is John;
         follow the scene changing rules;
     otherwise:
         say "I didn't understand that. Please type 'Alice' or 'John'.";
     reject the player's command.

When Pick Identity ends:
     now the command prompt is ">";
     now yourself is nowhere;
     say line break;
     try looking.

To say (T - a text) capitalized/capitalised:
     let temp be T;
     replace the regular expression "^(\w)" in T with "\u1";
     say T;

To say (O - an object) capitalized/capitalised:
     let temp be "[O]";
     say temp capitalized;

Dormitory Hallway is a room. "This is the hallway of the dormitory. [Dorm room 1 capitalized] is to the west and [dorm room 2] is to the east."

A dorm room is a kind of room.
Occupancy relates various dorm rooms to one person (called the occupant).
The verb to be occupied by means the occupancy relation.
The verb to occupy means the reversed occupancy relation.
Dorm room 1 is occupied by John.
Dorm room 2 is occupied by Alice.

Rule for printing the name of a dorm room (called item) while printing a heading:
     say "[regarding the occupant of item][Possessive] Dorm Room[unmention the occupant]".
Rule for printing the name of a dorm room (called item):
     say "[regarding the occupant of item][possessive] dorm room[unmention the occupant]".

Dorm room 1 is a dorm room.
Dorm room 1 is west of hallway.
The description of dorm room 1 is "[We]['re] in [dorm room 1]. [We] [can] leave to the east."

Dorm room 2 is a dorm room.
Dorm room 2 is east of hallway.
The description of dorm room 2 is "[We]['re] in [dorm room 2]. [We] [can] leave to the west."

John is a man.
The description of John is "[John] [look] no different from last time you saw [them]."
John is in dorm room 1.
Persuasion rule for asking John to try going: persuasion succeeds.

Alice is a woman.
The description of Alice is "[Alice] [look] no different from last time you saw [them]."
Alice is in dorm room 2.
Persuasion rule for asking Alice to try going: persuasion succeeds.