As we've seen in earlier examples such as "Equipment List", it is possible to vary the way Inform creates inventory listings in general (to create lists that look more like paragraphs of prose, lists divided between what the player is wearing and what he isn't, and so on). We can also use activities to alter the printing of specific objects' names and contents, as with the "omit contents in listing" feature after printing the name of something.
We may find, however, that we would like a great deal more control over Inform's printing of inventory details, not just as a special effect for a few items, but throughout the game.
We start by turning off Inform's native property writer:
"Oyster Wide Shut"
Section 1 - Procedure
The print standard inventory rule is not listed in any rulebook.
Carry out taking inventory (this is the new print inventory rule):
say "You are carrying: [line break]";
list the contents of the player, with newlines, indented, including contents, with extra indentation.
This is very much like the library's standard behavior, but with the exception that "giving inventory information" or even "giving brief inventory information" are omitted. Here's how we supplant it:
After printing the name of something (called target) while taking inventory:
follow the property-aggregation rules for the target.
Now, our property-aggregation rulebook is going to look at a given object and decide on a list of features that should be mentioned in inventory. We'll start by producing something quite similar to Inform's default behavior:
The property-aggregation rules are an object-based rulebook.
The property-aggregation rulebook has a list of text called the tagline.
A first property-aggregation rule for an openable open thing (this is the mention open openables rule):
add "open" to the tagline.
A first property-aggregation rule for an openable closed thing (this is the mention closed openables rule):
add "closed" to the tagline.
A property-aggregation rule for a closed transparent container which contains nothing (this is the mention empty transparent containers rule):
add "empty" to the tagline.
A property-aggregation rule for an open container which contains nothing (this is the mention empty open containers rule):
add "empty" to the tagline.
A property-aggregation rule for a lit thing (this is the mention lit objects rule):
add "providing light" to the tagline.
A property-aggregation rule for a thing worn by the player (this is the mention worn objects rule):
add "being worn" to the tagline.
The last property-aggregation rule (this is the print aggregated properties rule):
if the number of entries in the tagline is greater than 0:
say " ([tagline])";
rule succeeds;
rule fails.
Notice that we don't need to write any rules about how to print that list of text: because Inform is printing out a list, it will automatically insert commas, spaces, and the word "and" where appropriate; and it will automatically follow the "use serial comma" option, if we have it set.
Now we're free to meddle. Let's give the player a bunch of possessions that will be listed in interesting ways in inventory:
Section 2 - Scenario
The Curved Beach is a room. "White sand stretches away both northeast and northwest, enclosing this attractive little bay. Gentle waves lap at the beach."
The player carries a glowing plastic sack. The glowing plastic sack is lit and transparent and openable and open. It contains a rock. It is wearable.
The player wears a flashlight lanyard. The flashlight lanyard is a device.
Carry out switching on the lanyard: now the noun is lit.
Carry out switching off the lanyard: now the noun is unlit.
The player carries an oyster. The oyster contains a pearl. The oyster is openable.
Now suppose that we don't want the oyster to say "closed" when it's closed. Instead, we'd like it to say "clamped shut". As this is the only property the oyster will ever have, we can simply override his whole property-aggregation rulebook:
A property-aggregation rule for the oyster:
if the oyster is closed:
say " (clamped shut)";
rule succeeds.
That's fine for the oyster because "clamped shut" is the only property he'll ever have. What if we'd like instead just to revise the way the sack (and only the sack) gets described as providing light?
The sacklight rule is listed after the mention lit objects rule in the property-aggregation rules.
A property-aggregation rule for the plastic sack (this is the sacklight rule):
if "providing light" is listed in the tagline:
remove "providing light" from the tagline;
add "gently glowing" to the tagline.
Now the flashlight (and any other regular light sources we might add to the game) will be described as "providing light", but the sack will only be said to be gently glowing -- a bit more appropriate for its rather fainter gleam.
We might also wish to add a systematic feature across the board to include a new property in the inventory list? Let's say the player can enchant his possessions, and enchanted possessions should thereafter be listed accordingly:
A thing can be magical or non-magical. A thing is usually non-magical.
Understand "enchant [something]" as enchanting. Enchanting is an action applying to one thing.
Carry out enchanting something:
now the noun is magical.
Report enchanting something:
say "Ding! You turn [the noun] magical."
A property-aggregation rule for a magical thing:
add "enchanted" to the tagline.
Test me with "i / close oyster / i / turn on flashlight / i / take off flashlight / i / turn off flashlight / i / close sack / i / open sack / i / take all from sack / i / close sack / i / wear sack / i / enchant sack / i / open sack / put all in sack / i / close sack / i".
Further variations are possible as well: if we used a "before printing the name..." rather than an "after printing the name..." rule, we could automatically generate lines like "an open and empty phosphorescent plastic sack", removing some of the artificiality of the parentheses.
Or we could add more logic to the rules about which properties are mentioned, so that some features of objects were mentioned in inventory only if the player was wearing the correct detection device, like so:
The player wears enchantment-detecting goggles.
A property-aggregation rule for a magical thing:
if the player is wearing the goggles:
add "enchanted" to the tagline.
Most of the phrase options above are relatively self-explanatory; a few are less so. Here is an overview:
"With newlines" tells Inform to put a new line before each listed object. Indented tells it to indent contents of objects, when listing these.
"Giving inventory information" means to append information such as (closed) or (being worn) to objects.
"As a sentence" means to put "and" before the last object and commas between them; this is usually not used in conjunction with newline listing. "As a sentence" obeys whatever conventions about the use of the serial comma we may have established with the "Use serial comma" option.
"Including contents" means to list the contents of open or transparent containers and all supporters, whereas including all contents means to list the contents of all containers, even opaque closed ones.
"Tersely", perhaps unexpectedly, puts parentheses around objects listed as the contents of other objects.
"Giving brief inventory information" omits most of the inventory tags, such as "(open)" and "(worn)", but does list "(closed)" for closed containers which might not otherwise be obviously openable.
"Using the definite article" means prefixing objects with "the", if applicable, rather than "a".
"Listing marked items only" means including only objects that have already been declared "marked for listing".
"Prefacing with is-are" means that Inform will write "is" before the list if it contains only one item, and "are" if the list contains more than one.
"Not listing concealed items" means to omit from the list anything which is scenery.
Finally, "with extra indentation" means that the whole list should be indented slightly, in emulation of the default inventory listing.
With this information, we can try rewriting the inventory behavior to emulate the standard or to explore alternate versions:
"Equipment List"
The Watery Room is a room. The player carries a snorkel and a waterproof sack. The waterproof sack contains an undersea map, a diving guide, a cup, and 500 Argentine pesos. The cup contains a worm. The player wears a swimsuit and a pair of flippers. The sack is openable and open.
Inventory listing style is a kind of value. The inventory listing styles are tall, wide, curt, minimal, divided tall, and divided wide. Current inventory listing style is an inventory listing style that varies.
Understand "inventory [inventory listing style]" as requesting styled inventory. Requesting styled inventory is an action applying to an inventory listing style. It is an action out of world.
Carry out requesting styled inventory:
now current inventory listing style is the inventory listing style understood.
Report requesting styled inventory:
say "Inventory listing is now set to [current inventory listing style]."
We begin by emulating the standard inventory listing style:
Instead of taking inventory when current inventory listing style is tall:
if the number of things enclosed by the player is 0, say "You are empty-handed." instead;
say "You are carrying: [line break]";
list the contents of the player, with newlines, indented, giving inventory information, including contents, with extra indentation.
Here we offer the alternative of listing everything together as a paragraph:
Instead of taking inventory when current inventory listing style is wide:
if the number of things enclosed by the player is 0, say "You are empty-handed." instead;
say "You are carrying ";
list the contents of the player, giving inventory information, as a sentence, including contents;
say "."
This may be unsatisfactory, however. Items that are inside other items are not set off from those merely carried by the player. One way around this is to use terse listing, giving such descriptions as "a waterproof sack (in which are an undersea map, a diving guide, a cup (in which is a worm) and a 500 Argentine pesos)" as opposed to the more confusing " a waterproof sack (open), inside which are an undersea map, a diving guide, a cup, inside which is a worm and a 500 Argentine pesos".
Instead of taking inventory when current inventory listing style is curt:
if the number of things enclosed by the player is 0, say "You are empty-handed." instead;
say "You are carrying ";
list the contents of the player, tersely, giving brief inventory information, as a sentence, including contents;
say "."
If, using the above style, we close the sack, we will still get "(closed)" after the sack's listing. The following minimalist listing style abolishes even that nicety:
Instead of taking inventory when current inventory listing style is minimal:
if the number of things enclosed by the player is 0, say "You are empty-handed." instead;
say "You are carrying ";
list the contents of the player, tersely, as a sentence, including contents;
say "."
If we want to list worn things separately from carried things, we have occasion to put "listing marked items only" to work:
Instead of taking inventory when the current inventory listing style is divided wide:
if the number of things enclosed by the player is 0, say "You are empty-handed." instead;
say "You are wearing ";
now all things enclosed by the player are unmarked for listing;
now all things worn by the player are marked for listing;
if no things worn by the player are marked for listing, say "nothing";
otherwise list the contents of the player, as a sentence, listing marked items only;
say ".[paragraph break]";
say "You are carrying ";
now all things carried by the player are marked for listing;
now all things worn by the player are unmarked for listing;
if no things carried by the player are marked for listing, say "nothing";
otherwise list the contents of the player, as a sentence, tersely, giving brief inventory information, listing marked items only;
say ".[paragraph break]".
And similarly for a tall divided inventory:
Instead of taking inventory when the current inventory listing style is divided tall:
if the number of things enclosed by the player is 0, say "You are empty-handed." instead;
if the player carries something:
now all things enclosed by the player are unmarked for listing;
now all things carried by the player are marked for listing;
say "You are carrying: [line break]";
list the contents of the player, with newlines, indented, giving inventory information, including contents, with extra indentation, listing marked items only;
if the player wears something:
now all things enclosed by the player are unmarked for listing;
now all things worn by the player are marked for listing;
say "You are wearing: [line break]";
list the contents of the player, with newlines, indented, including contents, with extra indentation, listing marked items only.
Test me with "i / inventory wide / i / inventory curt / i / close sack / i / open sack / inventory minimal / i / close sack / i / open sack / inventory divided wide / i / inventory divided tall / i / drop all / i / take all / take off swimsuit / take off flippers / i / i divided wide / i / wear swimsuit / drop all / i".
Inform has built-in commands for other people, and sometimes we may want to adjust the way these work without completely disabling and replacing the command. Suppose, for instance, that instead of
Kermit the Frog looks through his possessions.
we'd like someone taking inventory to report what he's got, thus:
Kermit the Frog says, "I seem to be carrying a microphone and wearing a hat and a trenchcoat."
To do this, we could replace the built-in report rule with a different one.
"Trying Taking Manhattan"
The loud inventory rule is listed instead of the report other people taking inventory rule in the report taking inventory rules.
This is the loud inventory rule:
unless the player is the person asked:
say "[The person asked] says, 'I seem to be carrying [a list of things carried by the person asked][if the person asked is wearing something] and wearing [a list of things worn by the person asked][end if].'"
Persuasion rule for asking someone to try doing something: persuasion succeeds.
Grand Central Station is a room. "Here you are in New York, New York. Any minute now someone is going to burst into song."
Kermit the Frog is a man in Grand Central Station. "Kermit the Frog stands nearby, enjoying being green." Kermit is wearing a hat and a trenchcoat. He is carrying a microphone.
Test me with "inventory / kermit, inventory".