We can add the handling of multiple objects to an existing action simply by adding in a line of grammar using "[things]". In response, Inform will consider every object accepted by the token, and perform the action once for each of those objects. Thus:
"Shawn's Bad Day"
The Treasury is a room. The vault is a lockable locked closed openable container in the Treasury. It is fixed in place. "A massive vault fills up one wall." The description is "The vault's system includes [a list of things which are part of the vault]."
A little green light, a little blue light, a little red light, a thin black pane of glass, a laser beam, a retinal scanner, a thumbprint ID plate, a dial, and a large lever are part of the vault.
The security guard is a man in the Treasury. The description is "His name is Shawn, and he doesn't look happy."
The description of the green light is "Off." The description of the blue light is "Tranquilly on." The description of the red light is "Angrily flashing."
Understand "examine [things]" as examining.
Test me with "examine all".
Suppose that we have a game in which groups of objects can have meaning apart from their individual significance -- perhaps there are spells that can only be cast by collecting just the right items in the same place.
In this case, one of the things the player might like to be able to do is look at several items together and get a special response, different from looking at the items individually.
To make this happen, we need to do several things:
(1) we need to create a version of the EXAMINE command that can apply to multiple objects at once.
(2) we need to correct the way Inform normally deals with multiple-object commands, because we want our group description to print only one time, and we want to avoid stubs such as "pear: ... apple: ..." before or after the group description.
(3) we need to define a way for Inform to identify interesting groups and describe them.
"The Left Hand of Autumn"
Section 1 - Procedure
Understand "examine [things]" or "look at [things]" as multiply-examining. Multiply-examining is an action applying to one thing.
Understand "examine [things inside] in/on [something]" or "look at [things inside] in/on [something]" as multiply-examining it from. Multiply-examining it from is an action applying to two things.
Group-description-complete is a truth state that varies.
Carry out multiply-examining it from:
try multiply-examining the noun instead.
Check multiply-examining when group-description-complete is true:
stop the action.
Carry out multiply-examining:
let L be the list of matched things;
if the number of entries in L is 0, try examining the noun instead;
if the number of entries in L is 1, try examining entry 1 of L instead;
describe L;
say line break;
now group-description-complete is true.
Before reading a command:
now group-description-complete is false.
Now for step 2, overriding Inform's usual output of names of objects:
The silently announce items from multiple object lists rule is listed instead of the announce items from multiple object lists rule in the action-processing rules.
This is the silently announce items from multiple object lists rule:
unless multiply-examining or multiply-examining something from something:
if the current item from the multiple object list is not nothing, say "[current item from the multiple object list]: [run paragraph on]".
Definition: a thing is matched if it is listed in the multiple object list.
We'll save our "to describe" phrase until Section 2, when we can give the game specific instructions about how to report different lists of objects.
Now, the player might also want to be able to refer to a group of item by some kind of group name, so let's add the option of creating a Table of Collective Names which will interpret these:
After reading a command:
repeat through the Table of Collective Names:
let N be "[the player's command]";
let Y be relevant list entry;
while N matches the regular expression "[name-text entry]":
replace the regular expression "(.*)[name-text entry](.*)" in N with "\1[Y]\2";
change the text of the player's command to N.
Report taking something:
say "You pick up [the noun]." instead.
And as a bit of polish, because we'd like SEARCH TABLE to have the same effect as EXAMINE ALL ON TABLE:
Understand "look on [something]" as searching.
Instead of searching something which supports at least two things:
let L be the list of things supported by the noun;
describe L.
Instead of searching something which contains at least two things:
let L be the list of things contained by the noun;
describe L.
Section 2 - Scenario
Eight-Walled Chamber is a room. "A perfectly octagonal room whose walls are tinted in various hues."
The display table is a supporter in the Chamber. A twig of rowan wood is on the table.
The player carries an apple and a pear.
A glove is a kind of thing. A glove is always wearable. Understand "glove" as a glove. The player carries a left glove and a right glove. The left glove and the right glove are gloves.
Now we define a few actual lists of items:
Fruit list is a list of objects which varies. Fruit list is { apple, pear }.
Glove list is a list of objects which varies. Glove list is { right glove, left glove }.
Arcane list is a list of objects which varies. Arcane list is { left glove, twig, pear }.
To describe (L - a list of objects):
sort L;
if L is fruit list:
say "Just a couple of fruits.";
otherwise if L is glove list:
say "It's a matched pair of fuzzy blue gloves.";
otherwise if L is arcane list:
say "To anyone else it might look like a random collection of objects, but these three things -- [L with definite articles] -- constitute a mystic key known as the Left Hand of Autumn. They practically hum with power.";
otherwise:
say "You see [L with indefinite articles]."
When play begins:
sort fruit list;
sort glove list;
sort the arcane list.
We sort the lists so that regardless of how we change the rest of the code (and the order in which objects are coded), the resulting list will always be in sorted order and ready to compare with the list of items the player wants to look at. And thanks to the "Reading a command" code we wrote earlier, we can also teach the game to understand the player's references to "the left hand of autumn" as a specific collection of items.
Table of Collective Names
name-text
|
relevant list
|
"left hand of autumn"
|
"[arcane list]"
|
"gloves"
|
"[glove list]"
|
"pair of gloves"
|
"[glove list]"
|
Test me with "x apple and pear / x left and right / put pear on table / put left glove on table / x all on table / put all on table / examine all on table / get apple, twig, pear / x all on table / search table".