Often we have some salient features of an object that we want to make sure the player notices whenever looking at the item in a room or in inventory. At other times, we may prefer to allow the name of the item to be printed bare. So for instance:
"Rules of Attraction"
A metal form is a kind of thing. A magnet is a kind of metal form.
Every turn:
repeat with item running through nonmagnetic metal forms which are not part of something:
if item is in a container which contains a magnet (called attractor):
say "[The item] sticks to [the attractor].";
now the item is part of the attractor.
The horseshoe magnet is a magnet carried by the player. The nail is a metal form carried by the player. The Barn is a room. In the Barn is a bucket. In the bucket is a metal form called the iron hook.
Definition: a thing is nonmagnetic if it is not a magnet.
Rule for printing room description details of a magnet (called attractor): if something is part of the attractor, say " (stuck to which [is-are the list of things which are part of the attractor])".
After printing the name of a magnet (called attractor) while taking inventory:
if something is part of the attractor, say " (stuck to which [is-are the list of things which are part of the attractor])".
Before taking a touchable thing which is part of a magnet (called attractor):
move the noun to the holder of the attractor.
Test me with "i / put horseshoe in bucket / look / get horseshoe / i / drop horseshoe / i / look / get all / put all in bucket / i / x magnet / get nail / i".
Suppose we want to prevent the player from touching anything electrified -- not just as a response to TOUCH OBJECT, but at any time when the action would require contact with the object in question.
"Electrified"
A thing can be safe or electrified. A thing is usually safe.
The Open Field is a room. "At this end of the field is a wire fence separating farm country from the government testing grounds beyond." The wire fence is an electrified thing in Open Field. It is scenery. The description of the wire fence is "Built into the fence is [a list of things which are part of the fence]." The scary box is an electrified container. It is part of wire fence. In the scary box is an alluring prize.
The player carries a flashlight, a grappling hook, a very thick rubber glove, and a length of rope. The glove is wearable.
This is the electrocution-wisdom rule:
if the player wears the very thick rubber glove, make no decision;
if the action requires a touchable noun and the noun is electrified, say "You fear touching [the noun]." instead;
if the action requires a touchable second noun and the second noun is electrified, say "You fear touching [the second noun]." instead.
The electrocution-wisdom rule is listed before the basic accessibility rule in the action-processing rules.
Before touching the scary box:
say "You can't help noticing a bright red sticker on the surface of the box." [This rule will fire even if we are not wearing the glove, because Before rules occur before basic accessibility.]
Instead of opening the scary box:
say "The scary box seems to be super-glued shut." [This one won't, because Instead rules occur after basic accessibility.]
Test me with "touch fence / touch box / open box / wear glove / open box".
The following example makes fairly ample use of material that we haven't seen yet, but gives some idea of the flexibility of every turn rules. Suppose we want to have a number of electrical devices, all of which may be powered by a set of batteries. The batteries will all need to be discharged as they are used (regardless of what device they happen to be controlling at the moment). So:
"Witnessed"
A battery is a kind of thing. A battery has a number called charge. The charge of a battery is usually 15.
Every turn:
repeat with hollow running through battery compartments:
if the hollow is part of a switched on device (called the machine):
if a battery (called cell) is in the hollow:
decrement the charge of the cell;
carry out the warning about failure activity with the machine;
if the cell is discharged, carry out the putting out activity with the machine;
otherwise:
carry out the putting out activity with the machine.
Warning about failure of something is an activity.
Rule for warning about failure of a device (called the machine):
if a random battery compartment which is part of the machine contains a battery (called the power source):
if the charge of the power source is 2, say "[The machine] is obviously going to go out quite soon."
Putting out something is an activity.
Rule for putting out a device (called the machine):
say "[The machine] loses power and switches off![line break]";
silently try switching off the machine.
A battery compartment is a kind of container. A battery compartment is usually closed and openable. One battery compartment is part of every device. Instead of inserting something which is not a battery into a battery compartment, say "Only batteries should go in a battery compartment."
And to get rid of annoying messages like "Which would you like to close, the flashlight or the flashlight's battery compartment?" when only the compartment is closable, we might add some understanding instructions:
Understand "turn on [device]" as switching on.
Understand "turn off [device]" as switching off.
Understand "open [openable closed thing]" as opening.
Understand "close [openable open thing]" as closing.
Understand "put [something] in [container]" as inserting it into.
Instead of opening a device, try opening a random battery compartment which is part of the noun. Instead of closing a device, try closing a random battery compartment which is part of the noun. Instead of inserting a battery into a device, try inserting the noun into a random battery compartment which is part of the second noun.
Instead of switching on an empty device:
say "Nothing happens, perhaps because there isn't a charged battery in [the noun]."
Instead of switching on a battery compartment which is part of a device (called the power user), try switching on the power user.
Definition: a device is empty:
if a random battery compartment which is part of it contains a battery (called the power source):
if the power source is discharged, yes;
no;
yes.
Definition: a battery is discharged if its charge < 1.
A light source is a kind of device. Carry out switching on a light source: now the noun is lit. Carry out switching off a light source: now the noun is unlit.
The flashlight is a light source. A D battery is a battery carried by the player.
The cassette recorder is a device. Every turn: if the cassette recorder is switched on, say "The cassette recorder hisses faintly."
Rule for warning about failure of the cassette recorder:
if a random battery compartment which is part of the cassette recorder contains a battery (called the power source):
if the charge of the power source is 2, say "The hiss from [the cassette recorder] begins to warble ominously."
The player wears a backpack. The backpack is openable. In the backpack is the flashlight and the cassette recorder.
The description of the cassette recorder is "Useful both for recording your notes and for capturing any odd ghostly sounds you may hear."
The description of the backpack is "An old familiar pack, which you know so well that you can find all its pockets and take things in and out of it in pitch darkness. To avoid it showing up oddly in photographs, it is entirely black, with no shiny or metallic attachments."
The description of the flashlight is "You bought a new one just for this occasion, because you were worried about bringing something too small or light. This is a heavy-duty flashlight with an adjustable-focus beam. The case is made of metal, rather than plastic, and there is a spare light-bulb inside as well. You've put a band of masking tape around the handle and written in your initials in red marker.
There is a piece of red cellophane attached to the business end of the flashlight to keep it from being overly bright."
The red cellophane is part of the flashlight.
Instead of doing something to the red cellophane: say "You need the cellophane on the flashlight so that using it does not completely destroy your night vision."
Thirtieth Street Station is a room. "A huge, high, rectangular room with coffered ceilings, which looks grand but mostly makes you feel lonely and small. There are long benches in rows down the middle of the room, and an information desk with the train times, and a series of ticket windows, none of which matters very much at the moment."
The benches are an enterable supporter. They are scenery in the Station. The information desk is scenery in the Station. Some ticket windows are scenery in the Station. Instead of examining scenery in the Station: say "You're fairly sure that whatever is going on here has nothing to do with [the noun]." Understand "window" as ticket windows.
The mural is fixed in place in Thirtieth Street. "At the north side of the station is a particularly pointless and empty annex to the main room. It is dominated by a huge relief of sorts, and this is what you remember." Understand "metal" or "relief" or "huge" as the mural. The description of the mural is "It is both stylized and confusing, but you think it might be supposed to represent the various tasks and occupations of Philadelphia's population. The portions closer to the ground look as though they have recently been subjected to a light dusting of talcum powder. No unusual prints are evident."
The wind chimes are fixed in place in Thirtieth Street. "Carefully attached to the wall with a piece of duct tape and a hook is a light-weight set of wind chimes. Someone else has been here before you, it seems." The description is "Several of your friends use wind chimes as a sort of ghost alarm, since ghosts sometimes cause very localized movements of air when there is no natural breeze."
And this last bit, borrowed from the chapter on Understanding, adds some special instructions to help Inform decide when the player is likely to be referring to a compartment and when he's likely to be referring to the device itself.
Does the player mean doing something other than searching to a battery compartment: it is unlikely. [We discourage Inform from choosing a compartment when the player uses just the name of a device or the word 'battery'.]
We also need to deal with commands like PUT BATTERY IN FLASHLIGHT, where Inform might construe BATTERY as the D battery, the flashlight's battery compartment, or the cassette recorder's battery compartment -- and might also construe FLASHLIGHT as either the flashlight's battery compartment or the flashlight itself.
Does the player mean inserting into a battery compartment:
if the noun is nothing:
it is very likely;
otherwise:
make no decision.
Does the player mean inserting a battery compartment into: it is very unlikely.
Does the player mean inserting something into a device: it is unlikely.
Does the player mean searching a battery compartment: it is very likely.
Test me with "test first / test second".
Test first with "i / open flashlight compartment / put battery in it / turn on flashlight / take d battery / open cassette compartment / turn on cassette / put battery in cassette compartment / turn on cassette / z / z / z / z".
Test second with "get d battery / put d battery in flashlight compartment / turn on flashlight / z / z / z / z / z / z / turn off flashlight / z / z / turn on flashlight / z".