Inform 7 Home Page / Documentation
§10.7. Electricity and Magnetism
Electrons are so tiny, and move so fast, that we will never want to simulate them in ordinary IF. So we simply regard electricity and magnetism as behaviours which are either present or not present, and which have instantaneous effects.
In Witnessed 1, batteries provide electricity to enable a "device" to work. Even if switched on, a device with no battery will be ineffective.
Larger voltages are exposed in Electrified, which makes certain items untouchable, and ensures that an experienced electrician will not even try.
Rules of Attraction provides for a magnet which attracts metallic items just strongly enough to stick together until pulled apart for any reason.
|Start of Chapter 10: Physics: Substances, Ropes, Energy and Weight|
|Back to §10.6. Ropes|
|Onward to §10.8. Fire|
Rules of Attraction
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:
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.
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])".
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.
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.
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.
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.]
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:
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;
carry out the putting out activity with the machine.
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."
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:
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.
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 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.
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.
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".