It is straightforward to make a rule that anything with parts must mention all those parts during an EXAMINE command:
"Control Center"
After examining a thing when something is part of the noun:
say "[The noun] includes [a list of things which are part of the noun]."
The Control Center is a room. "Here you are at the Control Center of the universe."
The Universe Management Computer is a fixed in place thing in the Control Center. "The Universe Management Computer sits directly before you, unguarded." The description of the Universe Management Computer is "The computer is so large that you would be unable to operate it all from one position. Alas, it does not come with a manual."
A chartreuse indicator light, an ennui meter, a golden knob settable to 15,000 positions, a toothpick dispenser, and a button labeled RESTART are part of the Universe Management Computer.
The command chair is an enterable supporter in the Control Center. It is pushable between rooms. "Because the computer is too large for you to reach all of the front panel from a standing position, there is a command chair on casters which allows you to push back and forth." The description of the command chair is "Quite ordinary, really, but for the heady rush of power that comes of sitting in it.". Some casters are part of the command chair.
Now whenever we look at any object with components, we will first see the description, then a list of parts which belong to it. The following refinement brings in elements of later chapters, but it may be worth noting: because we've written our rule as an "After examining...", anything that pre-empts the operation of the examine command will also prevent that rule from occurring. So for instance:
A hair-thick needle is part of the ennui meter.
Instead of examining the ennui meter: say "You can't be bothered."
...would not result in the needle being mentioned.
Test me with "x chair / x computer / x ennui meter"
Suppose we want to let the player build a fishing pole out of three parts: a hook, a string, and a stick.
There are several things we must account for here. One is that our combination verb should be insensitive to ordering: it shouldn't matter whether the player types COMBINE STICK WITH STRING or COMBINE STRING WITH STICK.
Second, we need to make sure that our implementation handles intervening stages of assembly gracefully. The player should be able to combine string and hook first, or string and stick first, and be able to complete the assembly in either case.
Our implementation here uses a table of lists to determine which combinations of inputs should produce which result object. Because we sort our lists before comparing them, we guarantee that the player's ordering doesn't matter: COMBINE STICK WITH STRING will have the same effect as COMBINE STRING WITH STICK.
What's more, our implementation could be expanded to account for many other assemblages, if we wanted object-building to be a running theme of puzzles in our game.
"What Makes You Tick"
Understand "combine [something] with [something]" as combining it with. Combining it with is an action applying to two carried things. Understand the command "connect" as "combine".
Understand the command "attach" as something new. Understand "attach [something] to [something]" as combining it with.
The combining it with action has an object called the item built.
Setting action variables for combining something with something:
let X be a list of objects;
add the noun to X;
add the second noun to X;
sort X;
repeat through the Table of Outcome Objects:
let Y be the component list entry;
sort Y;
if X is Y:
now the item built is the result entry.
Check combining it with:
if the item built is nothing or the item built is not in limbo,
say "You can't combine [the noun] and [the second noun] into anything useful." instead.
Carry out combining it with:
move the item built to the holder of the noun;
now the noun is nowhere;
now the second noun is nowhere.
Report combining it with:
say "You now have [an item built]."
Limbo is a container. Limbo contains a hookless fishing pole, a hooked line, and a complete fishing pole.
Streamside is a room. The player carries a stick, a wire hook, and a string.
Table of Outcome Objects
component list
|
result
|
{stick, string}
|
hookless fishing pole
|
{wire hook, string}
|
hooked line
|
{hooked line, stick}
|
complete fishing pole
|
{hookless fishing pole, wire hook}
|
complete fishing pole
|
Test me with "combine stick with string / i / combine pole with hook / i".
This kind of implementation makes sense if we don't intend the player to take the fishing pole apart again, or to refer to any of its component parts once it is built. For an alternate approach that does allow assembled objects to be taken apart again, see "Some Assembly Required".
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.
"Signs and Portents"
Seven Dials is a room. The description of Seven Dials is "There is a signpost, on which seven hands swivel and swing, freely as weathercocks. They make your present road now London, now Abingdon; now Weston-super-Mare, or now Hell."
Seven Dials contains a signpost. The signpost is scenery. Understand "sign" and "post" as the signpost.
Destination is a kind of value. The destinations are London, Abingdon, Luton, Weston-super-Mare, Runnymede, Hell, and Low Noon.
The signpost has a destination.
In order to interact with the signpost, we will need to make use of some action rules:
Instead of examining the signpost:
say "[The signpost] currently puts you on the road to [italic type][the destination of the signpost][roman type], but it swiftly alters again.";
now the destination of the signpost is the destination after the destination of the signpost.
Instead of turning the signpost:
now the destination of the signpost is the destination after the destination of the signpost;
say "With a hand's touch you turn the signpost to mark your way for [italic type][the destination of the signpost][roman type]."
Instead of going north in Seven Dials when the destination of the signpost is Hell:
say "It is a path that goes gently ever down and down with no stumbling block or any distraction at either side; there are no bandits and no tolls.";
end the story.
Instead of going north in Seven Dials when the destination of the signpost is Low Noon:
say "A long road whose scenery does not change, nor anything on the horizon move but the sun. When at last you come to Noon, she hangs above your head like a hat.";
end the story finally.
Test me with "x signpost / n / turn signpost / n / turn signpost / n / turn signpost / n / turn signpost / n".
Test more with "x signpost / n / turn signpost / n / turn signpost / n / turn signpost / n / turn signpost / turn signpost / n".