| Chapter 11: Phrases |

| 11.12. Phrase options

There are often several slightly different ways to perform a given task but which have substantially the same definition. In the following example:

> To go hiking, into the woods or up the mountain:
> if into the woods then say "Watch out for badgers.";
> if up the mountain then say "Better take your compass.";
> say "You go hiking."

...a phrase has been set up which can be used in three ways:

> go hiking;
> go hiking, into the woods;
> go hiking, up the mountain;

Note that commas must be used to divide these "phrase options" from the rest of the text of the phrase. Within the definition of the phrase, the option's name is a valid condition, and

> if up the mountain then ...

is true if the phrase was called with "up the mountain" specified and false otherwise, in the obvious way. A more substantial example from the standard rules is given by the Inform list-writer, which produces lists of things to specifications we choose. For instance:

> list the contents of Marley Wood, as a sentence, with newlines
> and including all contents;

Note that this phrase is allowed to have multiple options specified, whereas "go hiking" above was not: this is because it was defined thus:

> To list the contents of (something - an object), with newlines, indented, as a sentence, including contents, including all contents, giving inventory information, giving brief inventory information, using the definite article, listing marked items only, prefacing with is/are, not listing concealed items, suppressing all articles and/or with extra indentation: ...

The significant difference is the word "and/or" instead of "or", which signals that more than one option can apply at a time.

(As it happens, not all of the above options are equally useful: "not listing concealed items", for instance, is probably helpful only to people creating projects which mingle Inform 6 and Inform 7 material. "Concealed" is a concept no longer in use.)

144
| Example Equipment List Overview of all the phrase options associated with listing, and examples of how to change the inventory list into some other standard formats.

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: change current inventory listing style to 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 are marked for listing begin; say "nothing"; otherwise; list the contents of the player, as a sentence, listing marked items only; end if; 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 are marked for listing begin; say "nothing[paragraph break]"; otherwise; list the contents of the player, as a sentence, tersely, giving brief inventory information, listing marked items only; end if; 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 begin; 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; end if; if the player wears something begin; 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; end if. 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".

Previous | Contents | Next