"Bikini Atoll" by Edward Teller
The Hut and the Tropical Beach are rooms.
The conch shell is in the Hut. After taking the shell for the first time: say "As you gather the oddly-warm conch shell into your arms, you experience a sudden flash of deja-vu...[banner text]"; move the player to the Tropical Beach.
Rule for printing the banner text when the player is not carrying the shell: do nothing.
Test me with "look / examine shell / get shell / look".
(By tradition, and as a courtesy to all the people who have worked on Inform, authors ensure that the banner is printed some time near the beginning of each game played. So please only defer it, rather than suppress it altogether.)
Suppose that we have a series of games each of which allows the player to select a puzzle difficulty level. When the player plays a new game in the series, we want him to start out by default with the same difficulty level he faced earlier on, so we store this information in a small preferences file, as follows:
"Alien Invasion Part 23"
A difficulty is a kind of value. The difficulties are easy, moderate, hard, and fiendish.
Understand "use [difficulty] puzzles" as selecting difficulty. Selecting difficulty is an action out of world, applying to one difficulty.
Carry out selecting difficulty:
choose row 1 in the Table of Preference Settings;
now challenge level entry is difficulty understood;
say "Puzzles will be [challenge level entry] from now on."
The File of Preferences is called "prefs".
When play begins:
if File of Preferences exists:
read File of Preferences into the Table of Preference Settings;
choose row 1 in the Table of Preference Settings;
say "(The current puzzle difficulty is set to [challenge level entry].)"
Check quitting the game:
write File of Preferences from the Table of Preference Settings.
Table of Preference Settings
challenge level
easy
The Sewer Junction is a room.
Our preference file is restricted to a single option here for simplicity's sake, but we could keep track of more information -- whether the player preferred verbose or brief room descriptions, screen configurations, and so on.
If we were disposed to be somewhat crueler, we could use a similar method to make the player finish each episode of the series in order to "unlock" the next. All we would need to do is store a numerical password in our preferences file when the player finished a given level; the next level would check, say, the Table of Completed Levels for that password, and refuse to play unless the right number were present.
Suppose we want a game in which each scenario starts with the characters wearing hats -- randomly passed out. We might be tempted to write our scenario like this:
"Hatless"
The Costumery is a room. Larry, Curly, and Moe are men in the Costumery. Janine is a woman in the Costumery.
Rule for writing a paragraph about a person (called the target) who wears a hat (called attire):
say "[The target] is here, looking stylish in [an attire]."
Rule for writing a paragraph about a hatless person (called the target):
say "[The target] mopes about, hatless."
A hat is a kind of thing. A hat is always wearable. Definition: a person is hatless if he is not the player and he does not wear a hat.
The indigo bowler, the polka-dotted fedora, the pink beret, and the scarlet cloche are hats.
When play begins:
now every hat is worn by a random hatless person.
And we might hope that this would choose a new hatless person for each hat, but we would be wrong. It will instead choose one hatless person and put all the hats on him -- and everyone else has to go bare-headed. That's clearly no good. Let's try again:
"Hatless 2"
The Costumery is a room. Larry, Curly, and Moe are men in the Costumery. Janine is a woman in the Costumery.
Rule for writing a paragraph about a person (called the target) who wears a hat (called attire):
say "[The target] is here, looking stylish in [an attire]."
Rule for writing a paragraph about a hatless person (called the target):
say "[The target] mopes about, hatless."
A hat is a kind of thing. A hat is always wearable. Definition: a person is hatless if he is not the player and he does not wear a hat.
The indigo bowler, the polka-dotted fedora, the pink beret, and the scarlet cloche are hats.
When play begins:
now every hatless person wears a random hat.
But this selects one random hat and assigns it to each hatless person in turn -- so it will only wind up being worn by the last of them (since Inform knows that only one person can wear a hat at a time).
In this case, we do have to expand out our loop so that the game makes an explicit distribution:
"Hatless 3"
The Costumery is a room. Larry, Curly, and Moe are men in the Costumery. Janine is a woman in the Costumery.
Rule for writing a paragraph about a person (called the target) who wears a hat (called attire):
say "[The target] is here, looking stylish in [an attire]."
Rule for writing a paragraph about a hatless person (called the target):
say "[The target] mopes about, hatless."
A hat is a kind of thing. A hat is always wearable. Definition: a person is hatless if he is not the player and he does not wear a hat.
The indigo bowler, the polka-dotted fedora, the pink beret, and the scarlet cloche are hats.
When play begins:
repeat with item running through hats:
now the item is worn by a random hatless person.
Each time Inform considers the instruction "now the item is worn by a random hatless person", there is one fewer such person to choose from -- so we can guarantee that the hats are distributed one per customer and that all hats are distributed.
Hatless 3 is only guaranteed to work because the number of hats is less than or equal to the number of people; otherwise the final use of random will return "nothing" and then a problem message will appear during play.