"Radio Daze" by Jon Ingold
The Living Room is a room. "A long couch, set up so you can see your wireless set. Not that you need to see it, of course."
The long couch is an enterable scenery supporter in the living room. Instead of entering the long couch when the radio was switched off, say "Better turn the radio on before you get comfortable." Report entering the couch: say "You settle yourself down to listen." instead. Instead of listening when the radio is switched on, stop the action.
The radio is a device in the living room. The radio is switched off. "[if switched on]The radio burbles on[otherwise]The radio is off[end if]." Check switching off the radio when the player is on the long couch: say "You can't reach the radio from here." instead.
Every turn when the radio is switched on:
say "[one of]Two characters in the radio play have begun an argument[or]The argument continues[or]The play continues[stopping]: [one of]'Did not!'[or]'Did too!'[or]'Did I?'[or]'You did!'[or]'I couldn't have, Martha!'[or]'But you did, Tom!'[cycling]"
Test me with "sit on couch / turn on radio / sit on couch/ listen / g / g / g / g / g".
Named properties are not the only kind that Inform is able to understand referring to an object. We can also use unit and number properties to distinguish things from one another, as here, where televisions have aspect ratios:
"Aspect"
An aspect ratio is a kind of value. 16:9 specifies an aspect ratio.
A television is a kind of device. A television has an aspect ratio. Understand the aspect ratio property as referring to a television. Understand "European standard" as 16:9.
The Office is a room.
The widescreen TV is a television in the Office. The fifties TV is a television in the Office. The widescreen TV is 16:9. The fifties TV is 4:3.
Test me with "examine european standard tv / x 16:9 tv / x 4:3 tv".
We might want to allow every television to be tuned to a channel (a number property) which the player could refer to, so that
WATCH CHANNEL 13
TURN OFF CHANNEL 4
would be directed to the appropriate television object, if any television is turned on and tuned to the correct station. We might now write:
"Channel"
A television is a kind of device. A television has a number called the channel. Understand the channel property as referring to a television. Understand "channel" as a television.
The Office is a room. The widescreen TV is a television in the Office. The fifties TV is a television in the Office.
Changing the channel of it to is an action applying to one thing and one number.
Understand "tune [something] to [number]" or "change channel of [something] to [number]" as changing the channel of it to.
Check changing the channel of something to:
if the noun is not a television, say "[The noun] cannot be tuned to a channel." instead.
Carry out changing the channel of something to:
now the channel of the noun is the number understood.
Report changing the channel of something to:
say "You tune [the noun] to channel [number understood]."
Instead of examining a television:
if the noun is switched off, say "[The noun] is currently turned off." instead;
let the chosen channel be the channel of the noun;
if the chosen channel is a current channel listed in the Table of Television Channels:
choose row with current channel of the chosen channel in the Table of Television Channels;
say "[output entry][paragraph break]";
otherwise:
say "Snow fills the screen of [the noun]."
Table of Television Channels
current channel
|
output
|
0
|
"The screen of [the noun] is completely black."
|
4
|
"A gloomy female news anchor describes the latest car bomb in Baghdad: 104 dead today, and no sign of change."
|
5
|
"A couple of contestants in spangled scarlet outfits are performing an energetic paso doble."
|
13
|
"On-screen, Ichiro is up to bat with one man on second and no outs."
|
Test me with "change channel of fifties tv to 4 / x channel 4 / switch on fifties / x channel 4 / switch on widescreen / tune fifties tv to 5 / x channel 5 / x fifties tv / x channel 4".
Our previous implementation of televisions ("Channel 1") doesn't allow the player to type things like
TUNE FIFTIES TELEVISION TO CHANNEL 4
nor does it deal with player input like
TUNE TO CHANNEL 4 ON FIFTIES TELEVISION
or
TUNE TO CHANNEL 4
where no television is specified. When we are designing commands which involve two elements (here, a television and a channel number), it's usually a good idea to allow the player to specify those elements in either order, as we saw demonstrated briefly in "New commands for old grammar".
We might, therefore, want to add a few refinements: first by defining a "[channel]" token that will accept input of the forms "[number]" and "channel [number]", and second by creating some additional "Understand" lines that will accept variant versions of the player's input.
"Channel 2"
Section 1 - Televisions in General
A television is a kind of device.
A television has a number called the channel. Understand the channel property as referring to a television. Understand "channel" as a television.
Changing the channel of it to is an action applying to one thing and one number.
Understand "tune [television] to [channel]" or "change channel of [television] to [channel]" as changing the channel of it to.
Understand "tune [something] to [channel]" or "change channel of [something] to [channel]" as changing the channel of it to.
Understand "tune to [channel] on [television]" or "change to [channel] on [television]" as changing the channel of it to (with nouns reversed).
Understand "tune to [channel] on [something]" or "change to [channel] on [something]" as changing the channel of it to (with nouns reversed).
Understand "[number]" or "channel [number]" as "[channel]".
Check changing the channel of something to:
if the noun is not a television, say "[The noun] cannot be tuned to a channel." instead.
Carry out changing the channel of something to:
now the channel of the noun is the number understood.
Report changing the channel of something to:
say "You tune [the noun] to channel [number understood]."
Instead of examining a television:
if the noun is switched off, say "[The noun] is currently turned off." instead;
let the chosen channel be the channel of the noun;
if the chosen channel is a current channel listed in the Table of Television Channels:
choose row with current channel of the chosen channel in the Table of Television Channels;
say "[output entry][paragraph break]";
otherwise:
say "Snow fills the screen of [the noun]."
Table of Television Channels
current channel
|
output
|
0
|
"The screen of [the noun] is completely black."
|
Section 2 - The Scenario
The Office is a room.
The widescreen TV is a television in the Office. The fifties TV is a television in the Office.
And we add the scenario-specific content to our Table of Television Channels; in the case of channel 13, we provide for a changing sequence of events using text variations.
Table of Television Channels (continued)
current channel
|
output
|
4
|
"A gloomy female news anchor describes the latest car bomb in Baghdad: 104 dead today, and no sign of change."
|
5
|
"A couple of contestants in spangled scarlet outfits are performing an energetic paso doble."
|
13
|
"[one of]On-screen, Ichiro is up to bat with one man on second and no outs.[or]Ichiro has singled to first and the other man is on third.[or]The next batter is in the middle of flying out.[or]Everything looks rosy until the men in black pull off a double-play and retire the side.[or]The channel has cut to a commercial.[stopping]"
|
Test me with "test one / test two".
Test one with "change channel of fifties tv to 4 / x channel 4 / switch on fifties / x channel 4 / switch on widescreen / tune fifties tv to channel 5 / x channel 5 / x fifties tv / x channel 4".
Test two with "tune to channel 13 / widescreen / tune channel 13 to channel 5 / tune channel 5 to channel 3 / widescreen / x channel 3".
The built-in behavior of Inform is to print a line after a device is examined, saying whether the item is on or off. This is often inappropriate, and we could simply turn off that behavior in general by instructing Inform to ignore the "examine described devices rule" (see the chapter on rulebooks).
Perhaps, though, we would like continue to have a short passage about the action of any switched on device; we'd just like a little more control over what it says from time to time. And in that case, we might change the rule to give a new activity control over that portion of the description:
"Aftershock"
Section 1 - Showing actions
Showing action of something is an activity.
Rule for showing action of something (called item):
if the item is switched on, say "[The item] is switched on.";
otherwise say "[The item] is switched off."
Borrowing from the rulebooks chapter, we can replace the standard "examine described devices" rule with something that uses this activity.
The new described devices rule is listed instead of the examine devices rule in the carry out examining rules.
This is the new described devices rule:
if the noun is a device:
carry out the showing action activity with the noun;
now examine text printed is true.
Thus far we have essentially replicated the original behavior, but we've made it possible to write specialized behavior for devices, and to invoke that behavior in other places:
Report switching on something:
say "You flip a switch. ";
carry out the showing action activity with the noun instead.
This might be useful for an electric lamp kind:
Section 2 - Electric Lamps
An electric lamp is a kind of device.
Rule for showing action of an electric lamp (called item):
if the item is switched on, say "[The item] is lit[if the number of visible lit things is greater than 1], competing with [the list of visible lit things which are not the item][end if].";
otherwise say "[The item] is dark."
Carry out switching on an electric lamp: now the noun is lit. Carry out switching off an electric lamp: now the noun is unlit.
Section 2 - The Scenario
The time of day is 3:47 AM. When play begins, now the right hand status line is "[time of day]".
The Downstairs Hallway is a dark room. "The only room in the house with no furniture and almost nothing on the walls. At times like this you always notice the crack in the plaster, originating near the light fixture and running almost all the way to the wall."
A plastic jug of filtered water is in the Downstairs Hallway. The description is "Five gallons, not that that will last you very long, hot as it has been lately."
The crack is scenery in the Hallway. The description is "No, the ceiling isn't going to fall on you today."
The light fixture is an electric lamp in the Hallway. It is switched on, lit, and scenery. The description is "A plain globe of frosted glass containing the light bulb. Nothing special, and you never think about it except when, as now, you are forced to spend hours in this room."
The flashlight is an electric lamp carried by the player. The description is "A shiny red flashlight." The portable radio is a device carried by the player. The description is "A small battery-operated radio which you received for free with your subscription to US News & World Report. It has served you well through many earthquakes past."
And with our activity, we can override the flashlight's electric lamp behavior with new behavior:
Rule for showing action of the flashlight:
if the flashlight is switched on, say "A strong, narrow beam of light shines from the flashlight.";
otherwise say "It is currently switched off."
...or give special actions for the radio:
Rule for showing action of the radio:
if the radio is switched on, say "Through the static, you pick up pieces of discussion: a 6.7 on the Richter scale, epicenter... something about Topanga... but it crackles out again.";
otherwise say "The radio is silent. You're saving the batteries."
Instead of listening in the presence of the switched on radio:
carry out the showing action activity with the radio instead.
Test me with "examine light / switch light off / switch flashlight on / switch radio on / examine radio / examine flashlight".