| Chapter 9: Time |

| 9.5. Every turn

The passage of time in interactive fiction is broken up into a succession of turns, in each of which the player types a request and is given a response. Usually each such request triggers one action, but sometimes a whole sequence are fired off, as when the player types "get all" in a cluttered room.

One of the last things to happen in each turn is that Inform will apply any rules which have been set to occur "every turn", like so:

> Every turn, say "The summer breeze shakes the apple-blossom."

This is equivalent to writing:

> An every turn rule: say "The summer breeze shakes the apple-blossom."

Note that the text about blossom, which will quickly become tiresome, is said at the end of every turn, not at the beginning, and in particular not before the player's first opportunity to type a command.

As usual when defining rules, we can add stipulations: any condition can be attached using "when".

> Every turn when in the Orchard, say "The summer breeze shakes the apple-blossom."

> Every turn when the player can see the rotting fish, say "Your nose twitches involuntarily."

111
| Example Witnessed 1 A kind of battery which can be put into different devices, and which will lose power after extended use.

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 the hollow running through battery compartments begin; if hollow is part of a switched on device (called the machine) begin; if a battery (called cell) is in hollow begin; decrease the charge of the cell by 1; 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; end if; end if; end repeat. 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) begin; if the charge of the power source is 2, say "[The machine] is obviously going to go out quite soon."; end if. 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 compartment which is part of the noun. Instead of closing a device, try closing a random compartment which is part of the noun. Instead of inserting a battery into a device, try inserting the noun into a random 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) begin; if the power source is discharged, yes; no; end if; 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 (called the machine): if a random battery compartment which is part of the machine contains a battery (called the power source) begin; if the charge of the power source is 2, say "The hiss from [the machine] begins to warble ominously."; end if. 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 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'.] Does the player mean searching a compartment: it is very likely. Does the player mean inserting something into a device: it is unlikely. Does the player mean inserting a battery into a battery compartment: it is very likely. [However, we teach Inform to prefer to put batteries in battery compartments.] 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".

112
| Example Text Foosball A game of foosball which relies heavily on every-turn rules.

Previous | Contents | Next