Inform 7 Home Page / Documentation
§4.15. Assemblies and body parts
In the previous chapter, we saw that it was possible to make sub-parts of things. For instance,
The white door is in the Drawing Room. The handle is part of the white door.
creates a door with an attached handle. But what if we want to say that not just this door, but every door, should have a handle? To do this we first need to create a kind called "handle", since there will clearly need to be many handles. The solution is:
A handle is a kind of thing. A handle is part of every door.
"Every" is a loaded word and best used sparingly. A sentence like "A handle is part of every handle" would, if taken literally, mean that a handle takes forever to make and is never finished. Inform will reject this, but the moral is clear: we should think about what we are doing with "every".
We will usually want to work with smaller collections - not literally every room, but with a whole set of them all the same. We can do that like so:
A silver coin is a kind of thing. A banking room is a kind of room. Five silver coins are in every banking room.
The effect of sentences like these is to make what we might call "assemblies" instead of single things. When a banking room is created, so are five more silver coins; when a door is created, so is another handle. Such sentences act not only on items created later on in the source text, but also on all those created so far.
This is especially useful for body parts. If we would like to explore Voltaire's suggestion that history would have been very different if only Cleopatra's nose had been shorter, we will need noses:
A nose is a kind of thing. A nose is part of every person.
Of course, if we make an assembly like this then we had better remember that the player is also a person and also gets a nose. In fact slightly odd things can happen if we combine this with changing the identity of the player. This works:
Cleopatra is a woman in Alexandria. The player is Cleopatra.
A nose is a kind of thing. A nose is part of every person.
but if those lines are in reverse order then Cleopatra's nose is assembled before she becomes the player, with the result that it ends up called "Cleopatra's nose" rather than "your nose" in play - which is very regal but probably not what we want. To avoid this, settle the player's identity early on in the source text.
All of the assemblies above make objects. Most make these new objects "part of" existing ones, but as we saw, they can also be "in" or "on" them. In fact, though, assemblies work in much more general ways: they can assemble values of almost any kind, placed in almost any relationship. To make use of that, we need to create a new verb, a topic which won't be covered properly until a later chapter, but here goes:
A colour is a kind of value. The colours are red, green and blue.
Liking relates various people to various colours. The verb to like means the liking relation.
Every person likes a colour.
Now every time a person is created, so is a colour which that person will like. If there are two people in the world, the player and Daphne, then we now have five colours: red, green, blue, Daphne's colour and the player's colour. Alternatively, we can assemble the other way around:
A person likes every colour.
Now we're telling Inform that every time a colour is made, a new person is also made - someone who will like that colour. So this sentence effectively makes three new people, one who likes red, one who likes green, and one who likes blue.
"Being Prepared"
A jacket is a kind of thing. A jacket is always wearable.
A pocket is a kind of container. A pocket is part of every jacket. The carrying capacity of a pocket is always 2.
After examining a jacket:
let target be a random pocket which is part of the noun;
say "[The target] contains [a list of things in the target]."
Now we've created the rules that will govern any specific jackets we might happen to put in our game: each one will always have one pocket, which will be able to contain no more than two things. The description of "a list of things" is text with a list, which we will learn about further in a few sections.
Next we might want to create the environment and an actual example of the jacket kind:
Tent is a room. "A dome made of two flexible rods and a lot of bright green ripstop nylon. It bills itself as a one-man tent, but you'd call it a two-dwarf tent: there is no way to arrange yourself on its square floor so that you can stretch out completely."
The hoodie is a jacket. "Your hoodie is balled up in the corner." The description of the hoodie is "Both elbows are stained from yesterday's entrenching project."
The hoodie's pocket contains a Swiss army knife and a folded map. The hoodie is in the Tent.
Notice that, since Inform has created a pocket for the hoodie, we can now refer to it by name in our source, giving it any additional properties we need to define. Here we simply put a few items into it.
The player wears a whistle. The description of the whistle is "To frighten bears."
Test me with "x hoodie / get hoodie / get knife / get map / i / put hoodie in pocket / put whistle in pocket / put map in pocket / put knife in pocket / i".
Notice that Inform automatically refuses to put the hoodie into its own pocket: as a default, a container cannot contain something of which it is itself a part.
Suppose we're particularly mechanically-minded and would like a game in which all of our mechanical devices have buttons to turn them on and off.
"Model Shop"
An on/off button is a kind of thing.
Instead of pushing an on/off button which is part of a switched off device (called the machine):
try switching on the machine.
Here we are making a rule about how our hypothetical buttons will interact with the machines to which they belong. Instead of pushing... is a rule that pertains to actions, and we will learn more about these in the chapter on actions. "...which is part of a switched off device" provides a specific circumstance - this is only to apply to buttons that are stuck to a machines that can be turned on or off. "(called the machine)" tells Inform that if it finds such a device, it should thereafter refer to it as "the machine." (The called syntax is explained further in the chapter on Change.)
A set of three more rules will complete our instructions about using buttons to control devices:
Instead of pushing an on/off button which is part of a switched on device (called the machine):
try switching off the machine.
Instead of switching on an on/off button which is part of a device (called the machine):
try switching on the machine.
Instead of switching off an on/off button which is part of a device (called the machine):
try switching off the machine.
Then we hand out buttons with a free hand:
One on/off button is part of every device.
The Model Shop is a room. A model train is a fixed in place device in the Model Shop. A toy elephant is a device in the Model Shop.
Every turn when the model train is switched on:
say "The model train circles your feet, blowing small puffs of steam."
Every turn when the toy elephant is switched on:
say "The toy elephant waves its trunk at you."
Test me with "push model train's button / push elephant's button / g / switch off model train's button".
And now the game will have a model train's button and a toy elephant's button.
It may be that we want (as an added nuance) to add other names for these items. While we would want an assembly to create objects such as "Lucy's hand" and not "Lucy hand", it is entirely reasonable to want to talk about the model train button or the elephant button. We could define these additional names like so:
Understand "elephant button" or "button on elephant" as the elephant's button.
Understand "model train" or "model" or "train" as "[train]". Understand "[train] button" or "button on [train]" as the model train's button.
In the second case, we are defining [train] to mean any of the three phrases "train", "model", and "model train"; so "[train] button" will match "model train button" or "train button" or "model button" equally well. See the chapter on Understanding for more on how to create alternative phrasings for the player to use.
Suppose we want to write a game in which there are a number of chests. Each of these chests will be a container, but have a lid which is a supporter.
"U-Stor-It"
Section 1 - Assemblies and Supporters
A chest is a kind of container. A chest is always openable. A chest is usually fixed in place. A chest is usually closed. The specification of a chest is "Represents a container with a separately implemented lid; the lid is itself a supporter."
A lid is a kind of supporter. A lid is part of every chest. The specification of a lid is "A supporter attached to a chest, which can only support things when the chest is closed."
(The "specification" of a kind is not really a property, and is used instead to describe the kind in the Index. So the text of these specifications is never found in the game.) Of course, this doesn't get us very far. We will also want the game to correctly interpret variations on "open the chest" and "close the lid", redirecting actions appropriately.
Section 2 - Opening and closing
Before opening a lid which is part of a chest (called the item):
try opening the item instead.
Before closing a lid which is part of a chest (called the item):
try closing the item instead.
Before opening a chest (called the box) when something is on a lid (called the obstruction) which is part of the box:
repeat with item running through things on the obstruction:
say "(first removing [the item])";
try taking the item.
Instead of opening a chest when something is on a lid (called the item) which is part of the noun:
say "You'd have to remove [the list of things on the item] from the lid first." instead.
Instead of looking under a lid which is part of a chest (called the item):
try opening the item.
We may also want to be able to deal with "put in" and "put on" appropriately, even if the player names the wrong part of the object:
Section 3 - Insertion and Support
Before inserting something into a lid which is part of a chest (called the item):
try inserting the noun into the item instead.
Before putting something on a chest when a lid (called the item) is part of the second noun:
try putting the noun on the item instead.
Furthermore, we don't want the player to be able to put things on the lid while the chest is open:
Before putting something on a lid which is part of an open chest (called the item):
say "(first closing [the item])";
try closing the item.
Instead of putting something on a lid which is part of an open chest (called the item):
say "[The item] would need to be closed first."
And then we may also want a couple of rules for describing our assembled object nicely:
Section 4 - Description in Rooms
Instead of examining a closed chest when something is on a lid (called the top) which is part of the noun:
say "[The noun] is closed, and there [is-are a list of things on the top] on top."
After printing the name of a chest (called the item) while listing contents of a room:
if a lid (called the second item) which supports something is part of the item:
say " (on which [is-are a list of things on the second item])";
omit contents in listing.
Now we are free to create entire treasure rooms at a single blow:
Section 5 - U-Stor-It Facility
The U-Stor-It Facility is a room. The sea trunk, the shipping crate, and a metal box are chests in the U-Stor-It Facility. The metal box contains a sapphire, a gold coin, and a signed photograph of Babe Ruth.
Even though we have never explicitly defined it, the metal box has a "metal box's lid", which we can use at need.
The metal box's lid supports a small card. The description of the small card is "It reads, 'Back in 5 mins - Pandora.'"
Test me with "open trunk / x card / open metal box / put all in metal box / get card / put card on box".
Suppose that we're going to give every person in the game a nose, but we want references to a nose always to mean the nose of someone *else*, if the player is with one other person. Moreover, on some occasions we're going to be in sight of Rudolph, so actions directed at an unspecified nose should always prefer his.
This relies on a somewhat advanced technique from the Understanding chapter, but since it may become useful with assemblies and body parts, it is worth mentioning here.
"The Night Before"
The North Pole is a room. "Here it is: the famous Pole. From here you can go south (or south-south, or south-south-by-south); or, alternatively, take refuge inside a red-and-white-striped cabin." The cabin is scenery in the North Pole. Instead of entering the cabin, try going inside.
Santa is a man in the North Pole. "Santa is pacing around in the snow and trying to psych himself up for the big night."
Inside from North Pole is the Candy Cane Cabin. The description of the Cabin is "Striped red and white, but nothing can make this place seem warm and inviting since Mrs. Santa ran off with the Tooth Fairy."
The Ice Shelf is south of North Pole. "The ice here has been smoothed into a kind of runway for easy take-off, and ends in a cliff and cold arctic sea." Donner, Vixen, Blixen, and Rudolph are animals in the Ice Shelf.
A nose is a kind of thing. A nose is part of every person. The description of Santa's nose is "It's a bit ruddy. You don't like to mention it, but Santa's been dipping heavily into the Grey Goose since Mrs. Santa left town." The description of a nose is usually "Not terribly exciting." The description of Rudolph's nose is "See how it glows!"
Next, we'll teach Inform some vocabulary to distinguish between the player and everyone else:
Definition: a person is other if it is not the player.
Definition: a thing is selfish if it is part of the player and the player can see an other person.
Instead of examining a selfish nose:
say "You cross your eyes, but can't get a good look."
Here is the part that actually determines the preferences. "Does the player mean..." can result in five outcomes: "it is very unlikely", "it is unlikely", "it is possible" (the neutral default), "it is likely", and "it is very likely". This is discussed in greater detail in the Understanding chapter. Here, we want to discourage references to the player's own nose and encourage references to the nose of Rudolph, so:
Does the player mean doing something when the noun is a selfish nose or the second noun is a selfish nose: it is very unlikely.
Does the player mean doing something to Rudolph's nose: it is very likely.
And this part is just for decoration:
Rule for writing a paragraph about Rudolph:
say "The reindeer are already harnessed and waiting impatiently. The brilliance of [Rudolph]'s nose casts an eerie red glow over [the list of unmentioned animals in the location]."
Test me with "x nose / x my nose / x santa's nose / in / x nose / out / s / x my nose / x nose / x rudolph's nose / x donner's nose".