RB §11.1. Start-Up Features

When the story file starts up, it often prints a short introductory passage of text (the "overture") and then a heading describing itself, together with some version numbering (the "banner"). It is traditional that the banner must appear eventually (and one of the few requirements of the Inform licence is that the author acknowledge Inform somewhere, for which the banner is sufficient) but some designs call for a multi-turn prologue before the banner finally appears, and marks the start of play in earnest. Bikini Atoll demonstrates this.

If a story file represents the latest in a sequence of story files representing chapters in some larger narrative, it will need some way to pick up where its predecessor left off. This can be done with the aid of external files (in the Glulx format, at least). Alien Invasion Part 23 shows how.

Another task we might want to perform a the beginning of play is to arrange any randomized features that are supposed to change from one playing to the next. We can add such instructions with "When play begins" rule, as in:

When play begins:
    now the priceless treasure is in a random room.

Since we may want to do something a bit more complicated than this, Hatless ★★ demonstrates effective and ineffective methods of distributing multiple objects (in this case, one randomly-selected hat per person).

See also

Map for a way to generate a randomized maze at the start of play
Food for a way to choose a random piece of candy to be poisonous
Getting Acquainted for a way to choose a murderer from among the characters at the start of each story

Examples

382. Bikini Atoll

paste.png "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.)

440. Alien Invasion Part 23

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:

paste.png "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.

126. Hatless ★★

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:

paste.png "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:

paste.png "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:

paste.png "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.

RB §11.2. Saving and Undoing

A very few titles in the IF literature - very few being still too many, some would say - restrict the player's ability to save the story.

Removing the player's ability to UNDO is also a risky choice. Inform does provide the facility with the use option

Use undo prevention.

which makes it impossible to UNDO at any time (unless, that is, the player is playing on an interpreter that itself has a built-in UNDO feature -- these do exist). When it works, undo prevention safeguards a randomized story or combat session against brute-force solutions, but it also means that the player who makes even a minor mistake of typing will be stuck with the undesired results.

In many cases it may be preferable to use some subtler method to enforce random effects in a story. Several extensions exist for Inform that either allow selective manipulation of the UNDO command or rig randomization to prevent UNDO and replay attempts.

Examples

210. Spellbreaker

The answer is easy, but there is a trap:

Check saving the game when the location is the Vault: say "That spell does not work here." instead.

The trap is that "Before saving the game...", which might have been our first guess, does not work: because out of world actions are exempt from Before, Instead and After rules.

"Spellbreaker" pulls this unpleasant, but in context witty, stunt as part of a situation which is engineered to force the player to reason through a weighing-objects puzzle using the perfect strategy rather than by guesswork. The illusion that the situation is fair - not rigged against the player, that is - would collapse if the player could save the game and keep retrying possibilities in the light of knowledge gained from earlier attempts. The moral of this story is that any attempt to use in-world situations to influence out-of-world commands should be extremely uncommon.

211. A point for never saving the game ★★★

Here is one way to score this point with Inform:

Check saving the game for the first time: decrement the score.

That has the right effect, but it just isn't sneaky enough. Instead let us quietly keep track of how many times the player saves:

Check saving the game: increment the number of saves.
When play ends: if the number of saves is 0, increment the score.

Sneakier, certainly, but now we could get the bonus even if the game ends earlier on, so finally:

When play ends: if the number of saves is 0 and the score is 349, increment the score.

RB §11.3. Helping and Hinting

IF is difficult to play: often harder than the writer ever suspects. Players are held up by what is "obvious", and they stumble into unforeseen combinations, or spend inordinate amounts of time working on the "wrong" problems. Too much of this and they give up, or post questions on online forums. Against this, many IF authors like to include in-story hints.

There are many approaches, which differ on two main issues.

First: do we spontaneously offer help to the player? The difficulty here is detecting the player's need: Y ask Y? tries to spot aimlessness, while Solitude ★★ has a novice mode where it is reasonable to assume that help is almost always needed. On the other hand, suppose we require that the initiative come from the player. Will a novice know to type HELP? Query shows how to redirect any attempt to ask a direct question into a HELP request. At the other end of the scale, wearily experienced players may type HELP all the time, out of habit, cheating themselves of the fun of frustration: if so, Real Adventurers Need No Help ★★★ provides the nicotine patch against this addiction.

Second: how do we decide what help is needed? Normally the player only types HELP, which is unspecific. The simplest approach offers a menu, diagnosing the player's problem by obliging him to make choices: see Food Network Interactive. Listing all the possible problems in the story may give away too much, though, since players may not have reached the puzzles in question yet; so some authors prefer to create menus that adapt to the current state of the story (commonly called "adaptive hints").

Failing this, we can also try to parse commands like HELP ABOUT MICRODOT, as in Ish. Trieste ★★ takes a similar tack, except that instead of offering hints about puzzles, it offers help on story features (such as how to save), and lists all the available topics if the player types simply HELP.

Finally, and perhaps most stylishly, we can try to deduce what the player is stuck on from his immediate circumstances and from what is not yet solved: this needs a powerful adaptive hints system like the one in The Unexamined Life ★★★.

See also

Getting Started with Conversation for a way to redirect a player using the wrong conversation commands
Footnotes for another medium by which hints could perhaps be transmitted

Examples

111. Y ask Y?

Suppose we'd like to watch for signs that the player is floundering, and if we see them, recommend that he try the hints. There are probably more sophisticated diagnostics, but as a first cut, let's assume that a player who repeatedly reviews descriptions of objects he's already seen, looks around the room, and takes inventory, is at a loss for more productive activities. So then...

paste.png "Y ask Y?"

A thing can be examined or unexamined. A thing is usually unexamined. Carry out examining something: now the noun is examined.

Taking inventory is acting confused. Looking is acting confused. Examining an examined thing is acting confused.

After acting confused for the sixth turn:
    say "(If you are feeling lost, try typing HELP for suggestions.)"

And now we write a scenario which will, alas, rather encourage even a deft and clueful player to play as though he were hopelessly confused:

The story headline is "or: Bad Author, No Biscuit".

The description of a thing is usually "Hm. [The item described] reminds you quite a lot of [a random visible thing which is not the item described]."

The Yurt is a room.

Food is a kind of thing. Food is always edible. In the Yurt are a yam and a dish of yakitori. The yam and the yakitori are food. The description of food is "Well, at least it's not [a random edible thing which is not the item described]."

In the Yurt is an animal called a yapok.

The player wears a yukata. The player carries a yataghan.

Every turn:
    if a random chance of 1 in 2 succeeds and something is examined:
        say "Your eye is attracted by some kind of surreptitious movement from [the random examined thing].";
    otherwise if the player carries something and a random chance of 1 in 3 succeeds:
        say "[The random thing carried by the player] tries to slip from your grasp."

Test me with "x yam / x yam / look / x yam / i / look / i / help / quit".

And finally a little dollop of perversity from a later chapter:

Check quitting the game:
    say "You're sure? ";
    if player consents, say "[line break]You were getting close to a breakthrough, you know.[line break]";
    otherwise stop the action.

Understand "help" as a mistake ("You're doing fine! Just keep at what you're doing now.").

284. Food Network Interactive

"Basic Help Menu" is an extension that uses tables to provide a menu of instructions. Suppose we wanted to include this menu in our own game, but add a few custom menu items of our own:

paste.png "Food Network Interactive"

Include Basic Screen Effects by Emily Short. Include Menus by Emily Short. Include Basic Help Menu by Emily Short.

Table of Basic Help Options (continued)

title

subtable

description

toggle

"Recipes in This Game"

Table of Recipes

--

--

"Contacting the Author"

--

"If you have any difficulties with [story title], please contact me at fakeaddress@gmail.com."

--

This table is one that is pre-defined by the extension. By continuing it, we add a few additional items to the list.

And since we've promised a sub-menu of recipes:

Table of Recipes

title

subtable

description

toggle

"Salmon Tartare"

--

"First, be sure to buy extremely fresh salmon. Raw fish should be served on the day it was caught, if possible. To guarantee this, visit an Asian supermarket or specialty store, and buy salmon marked 'sashimi grade'..."

--

"Pecan Brownies"

--

"Begin by shelling half a pound of pecans..."

--

Whole Foods is a room.

To test it, type HELP and then experiment.

296. Ish.

paste.png "Ish."

Ichiro's Dubious Sushi Hut is a room. "Despite the allure of the dusty plastic sushi models in the window, you're beginning to have second thoughts about the selection of this particular restaurant for your rendezvous with Agent Fowler. There are no other patrons, for one thing. Afternoon sunlight filters lazily through the window and illuminates a number of empty glass-topped tables, at each of which is a chopstick dispenser (in form of cute ceramic cat) and a pitcher of soy sauce (sticky).

The sushi bar itself is what gives the most pause, however. Behind it sits an angry-looking Japanese woman, aggressively eating a Quarter Pounder with Cheese."

We can, when necessary, accept any text at all as a token:

Understand "help [text]" or "help about [text]" as getting help about. Understand the commands "instructions" or "hint" or "hints" or "menu" or "info" or "about" as "help".

Getting help about is an action applying to one topic.

After that, we can use "the topic understood" to refer to the text we read:

Carry out getting help about:
    if the topic understood is a topic listed in the Table of Standard Help:
        say "[explanation entry][paragraph break]";
    otherwise:
        say "You're out of ideas."

Table of Standard Help

topic

title

summary

explanation

"sushi"

"sushi"

"Really it's just vinegary rice"

"Popular misconception says that sushi inevitably entails raw fish, but it is in fact just rice with rice vinegar on it. It's just that the really good kinds have raw fish in."

"cucumber roll" or "cucumber"

"Cucumber roll"

"Sushi for people who are afraid of sushi"

"It is just rice and slivers of cucumber in the middle, and as long as you don't go too crazy with the wasabi, all should be well."

"california roll" or "california"

"California roll"

"Travesty of the sushi concept"

"It's. Fake. Crab."

"monkfish liver"

"monkfish liver"

"Expert eaters only"

"The odds of Ichiro's having this unusual delicacy is near zero."

"microdot"

"microdot"

"What you came here to deliver"

"There'll be time enough for that later. If Fowler ever turns up. Where is she, anyway?"

Since the player may not know what all the help options are, we might as well let him get an overview, as well.

Understand "help" as summoning help. Summoning help is an action applying to nothing.

Carry out summoning help:
    say "Help is available about the following topics. Typing HELP followed by the name of a topic will give further information.[paragraph break]";
    repeat through the Table of Standard Help:
        say " [title entry]: [summary entry][line break]".

Test me with "help / help about microdot / help cucumber / help california roll".

329. Query

First, we create a single "[query]" token so that we can capture all instances of such sentences in a single line:

paste.png "Query"

Blank Room is a room.

Understand "who" or "what" or "when" or "where" or "why" or "how" or "who's" or "what's" or "when's" or "where's" or "why's" or "how's" as "[query]".

Understand "[query] [text]" as a mistake ("[story title] understands commands, such as '[command prompt]examine [a random thing that can be seen by the player]', but not questions. For more instructions, type HELP.").

Test me with "who am I? / who are you? / where is this place?".

Now the game will respond to all questions novice players might type with this reminder to look for help information.

285. Trieste ★★

Suppose we are using an extension in which another author has defined some help topics for the player, and we want to amend them for our game.

We'll start with the portion of the text that we have inherited from the extension:

paste.png "Trieste"

Section 1 - Procedure

A help-topic is a kind of value. Some help-topics are defined by the Table of Standard Instructions.

Table of Standard Instructions

help-topic

reply

commands

"This game recognizes 150 common commands for forms of military attack. These include..."

saving

"To save the game, type SAVE. You will be prompted to supply a file-name for your saved game. If you'd like to return to play at that point again later, RESTORE the saved game."

Understand "help [help-topic]" as asking for help about. Asking for help about is an action out of world, applying to one help-topic.
Understand "help" or "help [text]" as a mistake ("Help is available on the following topics: [help-topics list]").

To say help-topics list:
    repeat through the Table of Standard Instructions:
        say "[line break] [help-topic entry]";

Carry out asking for help about:
    repeat through the Table of Standard Instructions:
        if the help-topic understood is the help-topic entry:
            say "[reply entry][paragraph break]";
            break.

Section 2 - Scenario

Now, let's imagine our game is a special one in which only a very limited supply of moves are allowed. In that case, we'll want to replace the information on commands:

Table of Standard Instructions (amended)

help-topic

reply

commands

"The only commands this game recognizes are HOLD, MOVE, CONVOY, SUPPORT MOVE, and SUPPORT HOLD. No others are necessary."

Board Room is a room. Mark is a man in the Board Room. "Russia (played by Mark) is also hovering over the board."

Guest Bathroom is south of Board Room. Lena and Rob are in the Guest Bathroom. Lena is a woman. Rob is a man.

Rule for writing a paragraph about Lena when Lena is in the Guest Bathroom and Rob is in the Guest Bathroom:
    say "[Lena] (Italy) and [Rob] (Great Britain) are having a hushed conversation while leaning against your good towels. They stop and stare at you when you come in."

Test me with "help / help commands / help saving".

400. Solitude ★★

Observation of novice IF players suggests that they often have a hard time figuring out how to get started, especially if they are encountering the game in a context where they don't have time to settle in and read instructions. Here we provide some training wheels to help them learn to communicate.

This is divided into several parts. The first part is the system of rules for general guidance, which could be excerpted and used anywhere. The second part is a scenario using these rules.

paste.png "Solitude"

Part 1 - General Rules

When play begins:
    say "Have you played interactive fiction before? >";
    now novice mode is whether or not the player consents.

The rationale for asking the question this way, and not another, is that novices asked whether they would like instructions very often say no, even if they need them.

Novice mode is a truth state that varies. Novice mode is true.

Stopping novice mode is an action out of world.
Starting novice mode is an action out of world.

Understand "novice mode off" or "novice off" as stopping novice mode.
Understand "novice mode on" or "novice on" as starting novice mode.

Carry out stopping novice mode: now novice mode is false.
Carry out starting novice mode: now novice mode is true.

Report stopping novice mode: say "Novice mode is now off."
Report starting novice mode: say "Novice mode is now on."

Before reading a command when novice mode is true:
    say "[line break]Some options to try:[line break]";
    follow the novice suggestion rules.

The novice suggestion rules is a rulebook.

A novice suggestion rule (this is the suggestion that he look rule):
    if not looking and not going, say " [bold type]look[roman type]".

A novice suggestion rule (this is the suggestion that he check inventory rule):
    if the player carries something and we are not taking inventory, say " [bold type]inventory[roman type] (I)".

A novice suggestion rule (this is the suggestion that he put things on rule):
    if the player carries something and a free-standing supporter is relevant, say " [bold type]put[roman type] something [bold type]on[roman type] [the list of relevant supporters]".

A novice suggestion rule (this is the suggestion that he take things rule):
    if a gettable thing is relevant, say " [bold type]take[roman type] [the list of gettable relevant things]".

A novice suggestion rule (this is the suggestion that he examine things rule):
    if an unexamined thing is relevant, say " [bold type]examine[roman type] (X) [the list of unexamined relevant things]".

A novice suggestion rule (this is the suggestion that he enter things rule):
    if a relevant thing is worth entering, say " [bold type]enter[roman type] [the list of worth entering relevant things], or [bold type]get out[roman type]".

A novice suggestion rule (this is the suggestion that he open things rule):
    if an unlocked openable thing is relevant, say " [bold type]open[roman type] or [bold type]close[roman type] [the list of unlocked openable relevant things]".

A novice suggestion rule (this is the suggestion that he lock things rule):
    if a closed lockable thing is relevant, say " [bold type]lock[roman type] or [bold type]unlock[roman type] [the list of closed lockable relevant things]".

A novice suggestion rule (this is the suggestion that he eat things rule):
    if the player carries an edible relevant thing, say " [bold type]eat[roman type] [the list of edible relevant things carried by the player]".

A novice suggestion rule (this is the suggestion that he wear things rule):
    if the player carries a wearable relevant thing, say " [bold type]wear[roman type] [the list of wearable relevant things carried by the player]".

A novice suggestion rule (this is the suggestion that he turn things on rule):
    if a device is relevant, say " [bold type]turn on[roman type] or [bold type]turn off[roman type] [the list of relevant devices]".

A novice suggestion rule (this is the suggestion that he go places rule):
    if a room is adjacent, say " [bold type]go[roman type][exit list][if in darkness] or try other directions in the dark[otherwise]".

A novice suggestion rule (this is the suggestion that he enter doors rule):
    if an open door is relevant, say " [bold type]go through[roman type] [the list of relevant open doors]".

A novice suggestion rule (this is the suggestion that he interact with people rule):
    if another person is relevant, say " [bold type]kiss[roman type] or [bold type]wake[roman type] [the list of relevant other people][if the player carries something], or [bold type]give[roman type] things [bold type]to[roman type] someone[end if]".

A novice suggestion rule (this is the suggestion that he ask for help rule):
    say " [bold type]help[roman type] to see a more complete set of instructions".

A novice suggestion rule (this is the suggestion that he turn off help rule):
    say " [bold type]novice mode off[roman type] to turn off this guidance".

Last novice suggestion rule:
    say "[line break]".

The suggestion about asking for help is no good unless we provide some. This might take any of a number of forms, but for the sake of example we'll use an easy way out:

Include Basic Screen Effects by Emily Short. Include Menus by Emily Short. Include Basic Help Menu by Emily Short.

After taking inventory when novice mode is true: say "To get rid of any of these objects, [bold type]drop[roman type] it."

A thing can be examined or unexamined. Carry out examining something: now the noun is examined.

A thing can be seen or unseen. A thing is usually unseen.

Definition: a thing is relevant if it is seen and it is visible. Before printing the name of something (called the target): now the target is seen; if novice mode is true, say "[bold type]". After printing the name of something: say "[roman type]".

Definition: a supporter is worth entering:
    if the player carries it, no;
    if it is enterable, yes.

Definition: a container is worth entering:
    if the player carries it, no;
    if it is enterable and it is open, yes.

Definition: a person is other if it is not the player. Definition: a person is another if it is other.

Definition: a thing is free-standing if it is in a room.

To say exit list:
    let place be location;
    let count be 0;
    repeat with way running through directions:
        let place be the room way from the location;
        if place is a room:
            increment count;
            say "[if count is greater than 1] or[end if] [bold type][way][roman type]".

Definition: a thing is gettable:
    if it is scenery, no;
    if it is fixed in place, no;
    if it is a person, no;
    if the player is carrying it, no;
    if the player is wearing it, no;
    yes.

Part 2 - On the Ground

Antarctic Research Station is a room. "Though not always the most stimulating of environments, the station is far from your ex-wife and most of the things in the world that annoy you, namely the other 6+ billion people. There is a second room to the south." The station contains a radio. The radio is a device. It is fixed in place.

South of the Station is Sitting Room. The description of the Sitting Room is "Just big enough for a very [comfortable chair]." The Sitting Room contains an enterable supporter called a comfortable chair. The chair is scenery. A monograph about penguins is in the Sitting Room.

Blistering Cold is a room. "It is white out here and very very very cold." The white door is a door. "[The white door] leads to [the other side of the white door]." It is west of the Blistering Cold and east of the Antarctic Research Station.

Test me with "i / x radio / x door / s / i / x chair / x monograph / sit in chair / get up / n / open door / enter door".

54. Real Adventurers Need No Help ★★★

Suppose we have an action called "asking for help" that gives the player some hints on request. We've also made it possible to turn this feature off, if the player would like to discourage himself from using the hints too much. Now we need a value that varies to keep track of whether hints are currently permitted or currently not permitted. So we might write:

paste.png "Real Adventurers Need No Help"

A permission is a kind of value. The permissions are allowed and denied.

Hint usage is a permission that varies. Hint usage is allowed.

And under the right circumstances, we change hint usage to denied:

Check asking for help for the first time:
    say "Sometimes the temptation to rely on hints becomes overwhelming, and you may prefer to turn off hints now. If you do so, your further requests for guidance will be unavailing. Turn off hints? >";
    if player consents:
        now hint usage is denied;
        say "[line break]Truly, a real adventurer does not need hints." instead.

Then we can refer back to this value later to decide whether we want to display the hint menu or not:

Check asking for help:
    if hint usage is denied, say "You have chosen to eschew hints in this game. Be strong! Persevere!" instead.

Asking for help is an action out of world. Understand "help" or "hint" or "hints" as asking for help.

The Realm of Terribly Unjust Puzzles is a room.

Carry out asking for help:
    say "Fine, since you're weak enough to ask: here is a complete walkthrough: GET EGG. PEEL EGG. SMELL EGG. DIVIDE YOLK INTO THREE PORTIONS. GIVE THE SMALLEST PORTION OF YOLK TO THE GOLDEN GOOSE. ASK THE GOOSE ABOUT WHETHER THE SWAN IS TO BE TRUSTED. GIVE THE LARGEST PORTION OF YOLK TO THE SWAN. DANCE CONGA. EAT MEDIUM PORTION. STAND ON HEAD. WEST."

Test me with "hint".

Note that it would probably be kinder to offer the player some intermediate level of help, in the actual event.

230. The Unexamined Life ★★★

Hint systems in IF come in a variety of flavors: some are a static, prewritten set of guidelines (which might exist in a menu or outside the game entirely); others are built in as part of the program, and attempt to adapt to the situation the player currently faces. Adaptive hints have the advantage that they are less likely to reveal information for which the player is not ready, and the disadvantage that they are more work for the author.

The exercise here is to write an adaptive hint system that will both respond in agile ways to the state of the world model and require a minimum of authorial fussing. We also want the player to be able to ask for a hint about any object he encounters in the game world: this will let him be specific and avoid accidentally receiving hints about the wrong puzzles.

Our baseline assumption is that a player may find a puzzle unsolvable for one of two reasons: he either hasn't seen the relevant clue, or he hasn't got the relevant equipment. If these are true, then he should be given hints about how to find this information, and then once he has it, more specific hints about the puzzle itself -- ending, as a last resort, with the exact command(s) he will need to use in order to bring about the solution.

In practice, there are other possibilities, but this will do for an example.

We begin by defining our relations:

paste.png "The Unexamined Life"

Use scoring.

Explaining relates one thing to various things. The verb to explain means the explaining relation.

Instead of hinting about something when something unexamined (called the clue) explains the noun:
    say "You're still missing some information that might be useful to understanding the problem. [More]";
    if player consents, try hinting about the clue.

Requiring relates one thing to various things. The verb to require means the requiring relation.

Instead of hinting about something when the noun requires something (called the implement) which is not carried by the player:
    say "You're missing an object that might be useful to resolving this problem. [More]";
    if player consents, try hinting about the implement.

Hinting about is an action applying to one visible thing. Understand "hint about [any thing]" as hinting about.

This allows us to create the most absolutely generic sort of hint -- boring, perhaps, but in practice the player often just needs a nudge about what part of the game world he should be examining for a solution:

Carry out hinting about:
    if something explains the noun, say "You might want to review [the list of things which explain the noun]. ";
    if the noun requires something:
        say "You should be sure that you have [the list of things required by the noun]. ";
    otherwise:
        say "Sorry, I can't advise you further on that.".

These things cover hinting about objects that are themselves puzzles. But what if the player asks for hints about a tool or piece of information because he doesn't know how to apply it yet? We might want to give some guidance there, as well.

Carry out hinting about something which explains something (called target):
    if target is unseen, say "[The noun] might prove useful information, sooner or later." instead;
    otherwise say "You could examine [the noun]." instead.

Carry out hinting about something which is required by something:
    say "[The noun] might be useful to have. [More]";
    if player consents:
        if a seen thing requires the noun, say "[The noun] may help with [the list of seen things which require the noun]." instead;
        otherwise say "There are [number of things which require the noun in words] problems for which [the noun] might come in handy." instead.

Now we have these general hints written, but we want to pre-empt them if the player has not yet fulfilled all the prerequisites.

Instead of hinting about something unseen:
    if the noun is visible:
        now the noun is seen;
        continue the action;
    say "Perhaps you should explore further. ";
    if the ultimate location of the noun is an unvisited room:
        try hinting about the ultimate location of the noun;
    otherwise:
        if the ultimate location of the noun is the location:
            say "You're in the correct room right now[if the visible shell of the noun is a thing]. Try further exploring [the visible shell of the noun][end if].";
        otherwise:
            try hinting about the ultimate location of the noun.

Instead of hinting about a visited room:
    say "There's a room you've visited, but you haven't exhausted all there is to see there. [More]";
    if player consents:
        say "Try going back to [the noun]. [More]";
        if player consents, direct player to the noun.

Instead of hinting about an unvisited room:
    say "There's a room you haven't yet visited. [More]";
    if player consents, direct player to the noun.

To direct player to (goal - a room):
    let way be the best route from location to the goal, using even locked doors;
    if way is a direction, say "Try going [way] to start your explorations.";
    otherwise say "Sorry, the route is an indirect one.".

Instead of hinting about a portable seen thing which is not visible:
    if the noun is scenery, continue the action;
    say "You have seen the item you need to solve this problem, but it's not in sight at the moment. [More]";
    if player consents:
        try hinting about the ultimate location of the noun.

And this business of "seen" things requires, of course, that we keep track:

A thing can be seen or unseen. A thing is usually unseen. The player is seen. After printing the name of something (called target): now the target is seen.

That "After printing..." rule means that as soon as the game automatically prints the name of an object, it tags that object as having been "seen" by the player. This requires just a little care on our part, that we never mention an object without using the game's printing rules. Still, it is much easier than most other possible forms of bookkeeping.

We also need to deal with the question of whether the player has examined an object, for those objects whose descriptions carry vital information:

A thing can be examined or unexamined. A thing is usually unexamined. Carry out examining something: now the noun is examined.

In practice, there might be other ways of getting vital facts, and in a more sophisticated puzzle game we might need a more sophisticated model to track this. But examined or unexamined will do for now.

To decide what room is the ultimate location of (item - a thing):
    let place be the holder of the item;
    while the place is a thing:
        let the place be the holder of the place;
    if the place is a room, decide on the place.

To decide what thing is the visible shell of (item - a thing):
    if item is visible, decide on the item;
    let place be the holder of the item;
    while place is a thing and place is not visible:
        let place be the holder of the place;
    if the place is visible, decide on the place.

To say more:
    say "[paragraph break]Shall I go on? > ".

That covers most of the generic hints, but let's also add some slightly more precise hints about a few kinds of objects that are especially important in the model world. These hints will probably not be very interesting to a seasoned IF veteran, but a novice player who does not know the wording or cannot guess what something might be for may still find them useful:

Carry out hinting about a locked lockable thing:
    say "You could unlock [the noun] with [the matching key of the noun]." instead.

Instead of hinting about a locked thing when the matching key of the noun is not carried by the player:
    if the player can see the matching key of the noun:
        say "Perhaps [the matching key of the noun] would help.";
    otherwise:
        say "[The noun] is locked. There must be a key around somewhere. [More]";
        if player consents, try hinting about the matching key of the noun.

Carry out hinting about a closed openable unlocked thing:
    say "You could open [the noun]." instead.

Carry out hinting about an open door:
    say "You could enter [the noun]." instead.

Carry out hinting about an unexamined thing:
    say "You might find out something if you examine [the noun]." instead.

Carry out hinting about an edible thing:
    say "You could eat [the noun]." instead.

Carry out hinting about a wearable thing:
    say "You could wear [the noun]." instead.

Carry out hinting about a pushable between rooms thing:
    say "You could push [the noun] some direction." instead.

Now to the actual objects in the game:

The Crypt is a room. "This squat, barrel-vaulted chamber runs roughly north-south. Along either side are the graves of Saxon kings and early bishops of the church long since gone to dust -- one [tomb] in particular looks undisturbed."

Notice that we used the bracketed tomb here: the tomb is scenery, and if we do not use the name-printing function, Inform will not register that we have mentioned it to the player.

The tomb is scenery in the Crypt. The tomb is openable and closed. The silver dagger is a thing in the tomb. Understand "tombs" as the tomb. The description of the silver dagger is "Gleaming in a soft light all its own. Its blade is figured with running deer and its hilt is made of horn." The wight requires the silver dagger. The tomb requires the pry bar.

Instead of opening the tomb when the player does not carry the pry bar:
    say "The lids are stone, too heavy for you to raise without some implement."

Now we can add specific hints to replace the generic ones:

Carry out hinting about the tomb:
    say "The lids are heavy, but you can open them when you carry the pry bar."

The rest of the hint system ensures that the player will not see this final suggestion until he has the pry bar, since the tomb "requires" the pry bar. Having the hint there doesn't excuse us from providing some alternate wording in case the player solves this not-very-difficult conundrum on his own, though:

Understand "pry [something] with [something preferably held]" as unlocking it with. Understand the commands "lever" or "prise" as "pry".

Instead of unlocking something with the pry bar, try opening the noun.

The wight is a man in the Crypt. "[The wight] lurks near the south exit." The description of wight is "Old English [italic type]wiht[roman type]: a thing, a creature. It is little more than the memory of a life ill-lived, but it lingers here." Understand "wiht" or "creature" or "ghost" as the wight.

Instead of going south in the presence of wight:
    say "The wight breathes chill into your face.

Your head swims, and you are aware that you no longer have the willpower to go in that direction."

Fresh Air is south from the Crypt.

After going to Fresh Air:
    increment the score;
    say "Congratulations, you have escaped!";
    end the story finally.

The inscription is fixed in place in the Crypt. "Someone has painstakingly carved [an inscription] into the wall above the door." The description is "Squinting, you decipher the Latin text: [italic type]Silver causes harm to those that live though dead[roman type]." The inscription explains wight.

The Treasure Chamber is north of the Crypt. "The walls are thick, the high windows promisingly barred with iron. But for all this there is no hint of any valuable stores remaining."

The pry bar is in the Treasure Chamber. "One of the window bars, rusted from its place, lies in a puddle of water." Understand "window" or "bars" as the pry bar. The description of the pry bar is "A few feet long, and not entirely rusted into uselessness yet."

Instead of giving the dagger to wight:
    say "The wight recoils, appalled."

Carry out hinting about wight:
    say "You will have to find some way to get wight to come in physical contact with the silver dagger, which he will certainly not do willingly. [More]";
    if player consents, say "You could, for instance, throw it at him." instead;
    otherwise stop the action.

Understand "touch [something] with [something]" as putting it on (with nouns reversed). Understand "hit [someone] with [something]" as putting it on (with nouns reversed).

Instead of attacking the wight:
    say "You can't force yourself to approach close enough for hand to hand combat: if, indeed, the wight has hands."

Instead of putting the dagger on wight:
    say "The wight fades out of your way without ever coming into contact with the dagger. Perhaps a more projectile method would work better."

Instead of putting something on wight:
    say "The wight dodges you."

Instead of throwing the dagger at wight:
    now the wight is nowhere;
    move the dagger to the location;
    increment the score;
    say "The dagger passes through its airy form with a rending like the rip of silk. The fragments dissipate at once."

The maximum score is 2.

Test me with "hint about wight / north / get bar / south / open tomb / get dagger / south / hint about wight / read inscription / hint about wight / attack wight / throw dagger at wight / south".

Note that, if using TEST ME to run through the solution on the Z-machine, we will have to answer a few yes/no questions along the way.

For Glulx, the code should instead read something like

paste.png Test me with "hint about wight / y / north / get bar / south / open tomb / get dagger / south / hint about wight / y / read inscription / hint about wight / y / attack wight / throw dagger at wight / south".

RB §11.4. Scoring

Not every work of IF allots a numerical score to the player: for some authors, this emphasises the idea of a story rather than a narrative. The simple sentence

Use scoring.

introduces the concept. Once this is included, Inform will provide built-in support for a single number measuring progress ("score"), and will expect to measure this against a maximum possible ("maximum score", which can either be set by hand or worked out automatically from a table of ranks).

In a story in which scoring exists, the player may choose to turn score notifications (such as "[Your score has just gone up by one point.]") on or off. The commands to do this are NOTIFY ON and NOTIFY OFF; the actions are called switching score notification on and switching score notification off. In the event that we need to amend the behavior of notification, we could do so by adding, removing, or modifying the elements of the check and carry out rulebooks for these commands; as in

Check switching score notification off:
    if the turn count is less than 10:
        say "You are still a novice, grasshopper. Allow your teacher to give you advice until such time as you are ready to go on alone."

If we wish to change the wording of the default message ("[Your score has..."), we may want to use the Responses system.

An especially insidious style of bug allows the player to type the same sequence of commands over and over, earning score endlessly for the same insight, and to avoid this it is usually safest to write source like:

After taking the Picasso miniature when the Picasso miniature is not handled:
    increase the score by 10;
    say "As they say in Montmartre: dude!"

We might also write our condition with "for the first time", like so:

After jumping for the first time:
    increase the score by 5;
    say "Boing! That was certainly entertaining."

But we should be careful not to use "for the first time" in scoring situations where it's possible for the player to try the action but fail. Inform counts even unsuccessful attempts towards the number of times an action is understood to have occurred, so if the player tries to jump and fails, his "for the first time" will be used up and he will never receive the score points.

If there are many "treasure" items like the Picasso miniature, it is best to be systematic, as in No Place Like Home ★★★. Bosch takes another approach to the same idea, by creating a table of point-earning actions that the player will be rewarded for doing; the FULL SCORE command will then play these back.

Mutt's Adventure ★★ demonstrates how we might add a scored room feature, such that the player earns a point when he first arrives at a special room.

A single number does not really sum up a life, or even an afternoon, and Goat-Cheese and Sage Chicken ★★★ and Panache ★★★ offer more detailed citations. Works that are more story than story may prefer to offer a plot summary of the player's experience to date in lieu of more conventional scoring.

Finally, Rubies ★★★ provides a scoreboard that keeps track of the ten highest-scoring players from one playthrough to the next.

Examples

220. Bosch

We could, if we wanted, make a table of stored actions all of which represent things that will earn points for the player. For instance:

paste.png "Bosch"

Use scoring.

The Garden of Excess is a room. The gilded lily is an edible thing in the Garden of Excess.

The Pathway to Desire is west of the Garden of Excess. The emerald leaf is in the Pathway.

Table of Valuable Actions

relevant action

point value

turn stamp

taking the emerald leaf

15

-1

eating the gilded lily

5

-1

(And our list would presumably continue from there, in the full game.)

The maximum score is 25.

After doing something:
    repeat through Table of Valuable Actions:
        if the current action is the relevant action entry and turn stamp entry is less than 0:
            now the turn stamp entry is the turn count;
            increase the score by the point value entry;
    continue the action.

Understand "full score" or "full" as requesting the complete score. Requesting the complete score is an action out of world.

Check requesting the complete score:
    if the score is 0, say "You have not yet achieved anything of note." instead.

Carry out requesting the complete score:
    say "So far you have received points for the following: [line break]";
    sort the Table of Valuable Actions in turn stamp order;
    repeat through the Table of Valuable Actions:
        if the turn stamp entry is greater than 0:
            say "[line break] [relevant action entry]: [point value entry] points";
    say line break.

Test me with "eat lily / w / full score / get leaf / full".

This system is tidy, but limited: we cannot give actions interesting names in the score list, like "seducing the pirate's daughter" or "collecting a valuable artifact". So it will not be ideal in all situations, but it has the virtue of being easy to extend, and of listing all of the player's successes in the order in which they occurred in his play-through.

136. Mutt's Adventure ★★

Suppose we want to reward the player the first time he reaches a given room. The "unvisited" attribute is useful for this: unlike such constructions as "going to a room for the first time", it doesn't develop false positives when the player has merely tried to go to the room in question. "Every turn when the player is in a room for the first time" is also unhelpful, because it continues to be true as long as the player is in a room on his first visit there.

paste.png "Mutt's Adventure"

Use scoring.

Section 1 - Procedure

A room can be scored or unscored.

Carry out going to a unvisited scored room:
    increment the score.

Section 2 - Scenario

The Incan Palace Compound is a room. "After numerous false leads through the jungles of Peru, and an arduous trek along the Amazon, you have arrived, at last, here: at Atagon, the lost city of untold treasure."

The startlingly intricate door is a door. It is inside from Incan Palace Compound and outside from the Treasure Room. "A door carved all over with figures of ancient gods, and protected by an assortment of gears and latches, [if open]stands open[otherwise]blocks progress[end if] towards [the other side of the intricate door]."

The description of the Treasure Room is "To your considerable surprise, the treasure room is stocked with art objects from a vast range of eras and geographical locations: beside the expected pre-Columbian gold there are Cycladic figurines, Chinese Tang-dynasty pottery, purses that might have been stolen from Sutton Hoo. [one of]If the British Museum developed a nasty expectorant cough, this is what you'd find in its hanky.[or][stopping]".

The Treasure Room is scored.

Test me with "in / out / in".

137. No Place Like Home ★★★

Suppose we want to assign scores for a whole range of objects the player might pick up. One systematic way to do this would be with a table of point values for things:

paste.png "No Place Like Home"

Use scoring.

The Hall of the Gnome King is a room. The emerald cow is a thing in the Hall of the Gnome King. The ivory chessman is a thing in the Hall of the Gnome King. The book of incantations is a thing in the Hall of the Gnome King.

Table of Point Values

item

score

cow

10

incantations

4

chessman

1

Report taking an item listed in the Table of Point Values:
    increase the score by the score entry;
    blank out the whole row.

Test me with "take all".

"Blank out the whole row" removes the line from the table, so that each award will occur only once. The player will not be able to earn more and more points by dropping and taking the same item again.

166. Panache ★★★

If we have a plot that branches and has multiple kinds of outcome, we might well want to assemble these into a plot summary in place of the more traditional score. One way to approach this is to build the scene information into a table, adding information when each scene ends.

We begin with a bit of setup:

paste.png "Panache"

The player is in a room called Beneath Roxane's Balcony. Christian is a man in the Balcony. "Christian stands in a spot of moonlight and tries to avoid too obviously glancing at the shadows that conceal you." The description of Christian is "Like you, Christian loves Roxane. Unlike you, he is handsome enough to receive her favor in return. He is the beauty to your brain."

Roxane is a woman in the Balcony. "Above you in the night is Roxane." Roxane can be wooed, skeptical, confused, or annoyed. Roxane is skeptical. The description of Roxane is "The brightest, the most radiant of women -- and in love with an utter fool."

Empty Street is a room. "No one is about at this hour, all alone under a pale moon."

Telling someone about something is speech. Asking someone about something is speech. Answering someone that something is speech.

This next portion borrows from the Advanced Actions chapter to allow us to command Christian to do things:

A persuasion rule for asking Christian to try speech: persuasion succeeds.

Carry out Christian answering someone that something:
    now Roxane is wooed;
    say "'[noun], [the topic understood].'"

Carry out Christian answering the player that something:
    say "Christian parrots your words back to you." instead.

Carry out Christian telling a skeptical Roxane about something:
    now Roxane is confused;
    say "Christian turns to [the noun]. 'I must tell you about [the topic understood],' he says, and comes to a halt, looking at you for further direction.

    Perhaps you'd better give him exact lines to say. Surely he can't mess up an instruction like 'say hello to Roxane.'" instead.

Carry out Christian asking a skeptical Roxane about something:
    now Roxane is confused;
    say "'So,' says Christian nervously to [the noun]. 'Did you know about [the topic understood]?' But Roxane merely seems puzzled." instead.

Carry out Christian telling a confused Roxane about something:
    now Roxane is annoyed;
    say "Christian begins rambling on witlessly about [the topic understood]." instead.

Carry out Christian asking a confused Roxane about something:
    now Roxane is annoyed;
    say "Christian puts another confused question about [the topic understood]." instead.

And now we have enough material to begin writing the scenes:

Courting Roxane is a scene. Courting Roxane begins when play begins. Courting Roxane ends in success when Roxane is wooed. Courting Roxane ends in failure when Roxane is annoyed.

When Courting Roxane ends in success:
    record "Seduction by Proxy" in the Table of Events;
    say "Roxane, deeply moved by this sentiment, invites Christian up to her balcony. He scrambles up the ivy and disappears into her bedroom; the last thing you hear is a girlish giggle from above.";
    now Roxane is nowhere; now Christian is nowhere;
    move the player to Empty Street.

When Courting Roxane ends in failure:
    record "Ruining Christian's Chances" in the Table of Events;
    say "Roxane sighs heavily and goes back into her room, slamming the door behind her.

'Thanks very much,' says Christian to you, striding off down the street.";
    now Roxane is nowhere; now Christian is nowhere;
    move the player to Empty Street.

Sulky Ramble is a scene. Sulky Ramble begins when Courting Roxane ends in success. Sulky Ramble ends when the time since Sulky Ramble began is 2 minutes. When Sulky Ramble ends: record "Wandering the Streets, Sulking" in the Table of Events.

Every turn during Sulky Ramble:
    say "You find yourself kicking fenceposts quite without thinking about it."

Smug Ramble is a scene. Smug Ramble begins when Courting Roxane ends in failure. Smug Ramble ends when the time since Smug Ramble began is 2 minutes. When Smug Ramble ends: record "Wandering the Streets, Exultant" in the Table of Events; say "Of course, you will regret this soon enough."

Every turn during Smug Ramble:
    say "You find yourself smiling fiercely at the moon."

To record (occurrence - text) in (target table - a table name):
    choose a blank row in the target table;
    now the event entry is the occurrence.

Table of Events
event
"A Duel of Insults"
with 30 blank rows.

The plot summary rule is listed instead of the announce the score rule in the carry out requesting the score rules.

This is the plot summary rule:
    say "The Plot So Far: [paragraph break]";
    let act number be 0;
    repeat through the table of Events:
        increment act number;
        say " Act [act number]: [event entry][line break]".

Test me with "christian, ask roxane about love / christian, say your breath smells like ripe taleggio to roxane / score / z / z / score".

280. Goat-Cheese and Sage Chicken ★★★

Some games provide a FULL SCORE command that gives more information about the player's achievements than SCORE alone. Supposing we wanted to include a FULL SCORE in our game that gave the kind of score reading described in this chapter:

paste.png "Goat-Cheese and Sage Chicken"

Use scoring.

The story headline is "An interactive recipe"

Table of Tasks Achieved

Points

Citation

Time

3

"sauteeing onions"

a time

3

"reconstituting apricots"

1

"flattening chicken"

1

"unwrapping goat cheese"

To record (T - text) as achieved:
    choose row with a citation of T in the Table of Tasks Achieved;
    if there is no time entry:
        now time entry is the time of day;
        increase the score by the points entry.

Requesting the full score is an action out of world. Understand "full" or "full score" as requesting the full score.

Carry out requesting the full score:
    if the score is 0, say "You have achieved nothing towards supper." instead;
    repeat through the Table of Tasks Achieved in reverse time order:
        say "[time entry]: [citation entry] ([points entry])."

Table of Rankings

Score

Rank

0

"Rank Amateur"

2

"would-be Bobby Flay"

5

"Alton Brown"

8

"Julia Child"

The Kitchen is a room. The description of the Kitchen is "Equipped with many familiar friends: refrigerator, stove, oven; countertop; cabinet for pans and bowls, and a drawer for your tools."

The stove is scenery in the kitchen. It is a supporter. The oven is a container. It is part of the stove. It is closed and openable. The stove's switch is a device. It is switched on. It is part of the stove. The oven's dial is a device. It is switched off. It is part of the oven.

A thing can be heatproof.

Instead of putting something which is not heatproof on the stove when the stove's switch is switched on:
    say "You catch yourself just at the last minute: not a good idea to put [the noun] directly on the stove while it's turned on."

Instead of switching on the stove, try switching on the stove's switch. Instead of switching off the stove, try switching off the stove's switch. Instead of switching on the oven, try switching on the oven's dial. Instead of switching off the oven, try switching off the oven's dial.

Before switching on the oven's dial when the oven is open:
    say "(closing the oven so that it will heat properly)[command clarification break]";
    try closing the oven.

The frying pan is a heatproof unopenable open container on the stove.

The cabinet is a closed openable container in the kitchen. It is scenery. It contains an open unopenable container called a mixing bowl. It contains a portable supporter called a platter. An open unopenable heatproof container called a Calphalon baking dish is in the cabinet. The baking dish has the description "One of those marvelous pieces of kitchen equipment which goes on the stove or in the oven, as you will. The chief thing is never ever to touch it when it is hot, since the handles are metal and the heat retention excellent."

The counter is a supporter in the kitchen. It is scenery. The kettle is a heatproof openable closed container on the counter. Some water is in the kettle.

The water can be cool, warm, or boiling. The printed name of the water is "[water condition] water".

The refrigerator is a closed openable container in the kitchen. It is scenery. Understand "fridge" as the refrigerator.

An ingredient is a kind of thing.

Some onions, some apricots, and some sage are ingredients on the counter. A chicken breast, an egg, and goat cheese are ingredients in the refrigerator.

The goat cheese can be wrapped, snipped open, or unwrapped. The printed name of the goat cheese is "[goat cheese condition] goat cheese".

The sage can be unwashed, clean, or julienned. The sage is unwashed. The printed name of the sage is "[sage condition] sage".

The apricots can be dried, reconstituted, or chopped. The apricots are dried. The printed name of the apricots is "[apricots condition] apricots".

The chicken breast can be whole, flattened, stuffed, rolled, coated, browned, or baked. The printed name of the chicken breast is "[chicken breast condition] chicken breast".

The onions can be unpeeled, peeled, diced, sauteed, or burnt. [The printed name of the onions is "[onions condition] onions".]

The can of chicken broth is a closed container on the counter. The bottle of white cooking wine and the bottle of Thurston Wolfe PGV are a closed containers in the refrigerator.

The description of the Thurston Wolfe is "A Washington State Pinot Gris-Viognier, 2003. It is said to have 'peach aromas', and, startlingly, the untutored person can detect these without resorting to fantasy.

(It is also supposed to possess a delicate perfume and a moderate body; the label author at least stopped short of 'good sense of humor and likes long walks on the beach')."

Understand the commands "wash" and "rinse" as "clean".

Instead of rubbing the unwashed sage:
    now the sage is clean;
    say "You rinse off the sage. There -- ready to slice."

Instead of cutting the sage:
    say "You'd need to have a knife in hand, first."

Instead of cutting the clean sage when the player is carrying the butcher knife:
    now the sage is julienned;
    say "You slice the sage into thin strips."

Instead of cutting the unwashed sage:
    say "It came from the garden, so it won't have any strange chemicals on it, but you should still give it a rinse for dirt and bugs and so on before using it."

Instead of doing something other than examining or rubbing with the unwashed sage:
    say "It needs to be washed off."

Understand "peel [something]" as peeling.

Peeling is an action applying to one thing.

Instead of peeling the unpeeled onions:
    now the onions are peeled;
    say "You tear away the shining outer skin of the onions, leaving them pale and nekkid. Poor things."

Instead of cutting the diced onions:
    say "That seems unnecessary now."

Instead of cutting the sauteed onions:
    say "Too late; you're well past that stage."

Instead of cutting the burnt onions:
    say "There's no rescuing 'em -- the carbon isn't going to flake off, you know."

Instead of cutting the unpeeled onions:
    say "It would help to peel them first."

Instead of cutting the peeled onions:
    say "You'd need to have a knife in hand, first."

Instead of cutting the peeled onions when the player is carrying the butcher knife:
    now the onions are diced;
    say "You dice the onions neatly. Your own skill brings tears to your eyes."

Instead of opening the goat cheese:
    try peeling the goat cheese instead.

Instead of peeling the unwrapped goat cheese:
    say "The goat cheese is already unwrapped. (Stay focused, stay focused...)"

Before peeling the wrapped goat cheese when the shears are held by the player:
    try cutting the goat cheese.

Instead of peeling the snipped open goat cheese:
    now the goat cheese is unwrapped;
    record "unwrapping goat cheese" as achieved;
    say "Ah, success. The goat cheese is now free of its packet."

Instead of peeling the wrapped goat cheese:
    say "It would help to have a pair of scissors or something -- the packet resists being torn."

Instead of cutting the goat cheese:
    say "No need, at this point."

Before cutting the wrapped goat cheese when the shears are not held by the player and the shears are visible:
    say "(first picking up the shears)[command clarification break]";
    try taking the shears.

Instead of cutting the wrapped goat cheese:
    say "Something to cut with would be useful."

Instead of cutting the wrapped goat cheese when the shears are held by the player:
    now the goat cheese is snipped open;
    say "You neatly snip through the packaging with the shears."

Instead of examining the whole chicken breast:
    say "It is still entire and has yet to be pounded flat."

Instead of examining the flattened chicken breast:
    say "It has been hammered to a thickness of about a half inch. (The recipe said a quarter inch but you're pretty sure it was joking. You have never been able to achieve a quarter inch.)"

Instead of attacking the whole chicken breast:
    say "You need something heavy enough to flatten it with."

Instead of attacking the whole chicken breast when the player is holding the wooden mallet:
    now the chicken breast is flattened;
    record "flattening chicken" as achieved;
    say "You hammer away at the chicken breast, turning all your aggressions into culinary goodness. Several minutes pass. When you are done you have a broad flat chickeny pancake suitable for wrapping about a stuffing."

Before printing the name of onions:
    say "[onions condition] ".

The drawer is an openable closed container. It is part of the counter.

A tool is a kind of thing. A spatula, a spoon, a wooden mallet, some shears, and a ball of twine are tools in the drawer. A butcher knife is a tool carried by the player. Understand "scissors" as the shears.

Instead of burning something:
    say "You'll have to do that the hard way."

Some steam is fixed in place. "Dense clouds of steam fill the room."

Some smoke is fixed in place. "Smoke is beginning to collect near the ceiling."

Sauteeing Onions is a scene. Sauteeing Onions begins when the diced onions are in a hot container.

Definition: a container is hot if it is on the stove and the stove's switch is switched on.

Instead of touching the hot pan:
    say "Ow!"

Scorching Onions is a scene.

Preheating the Oven is a scene. Preheating the Oven begins when the oven's dial is heating.

Definition: a oven's dial is heating if the oven's dial has been switched on for exactly one turn.

Preheating the Oven ends when the time since Preheating the Oven began is five minutes.

When Preheating the Oven begins:
    say "The oven begins to warm up."

When Preheating the Oven ends:
    say "The oven beeps to inform you that it has reached the desired hotness."

Every turn during Sauteeing Onions:
    say "The onions sizzle in the pan."

Every turn during Scorching Onions:
    say "The onions are past their prime and are getting blacker by the moment."

Every turn during Hearing the Kettle Whistle:
    say "The kettle continues to whistle."

Instead of listening to during Hearing the Kettle Whistle:
    say "The only thing you can really hear just at the moment is the kettle."

Instead of smelling the Kitchen during Sauteeing Onions:
    try smelling the onions.

Instead of smelling the onions during Sauteeing Onions:
    say "The onions smell marvelous."

Instead of opening the oven during Preheating the Oven:
    say "It'll never heat if you open it up while it's warming."

Heating Kettle is a scene. Heating Kettle begins when the hot kettle contains cool water.

Before printing the name of the kettle when the kettle is hot:
    say "hot "

When Heating Kettle begins:
    say "The kettle begins to heat up."

Heating Kettle ends when the time since Heating Kettle began is 7 minutes.

Hearing the Kettle Whistle is a scene. Hearing the Kettle Whistle begins when Heating Kettle ends. Hearing the Kettle Whistle ends when the kettle is not hot.

When Hearing the Kettle Whistle begins:
    now the water is boiling;
    say "The kettle begins to burble and whistle shrilly."

When Hearing the Kettle Whistle ends:
    say "The kettle's screaming dies off."

Idling is a scene. Idling begins when play begins. Idling ends when Sauteeing Onions begins.

Sauteeing Onions ends in disaster when Scorching Onions begins.

Sauteeing Onions ends in success when the onions are sauteed and onions are not in a hot container.

Definition: a thing is alone if it is in a container which contains exactly one thing.

Sauteeing Onions ends in mixture when the sauteed onions are not alone.

When Sauteeing Onions ends in mixture:
    say "The mixture of things in [the holder of the onions] stops them cooking quite so fast."

When Sauteeing Onions ends in success:
    say "Nice work with the onions."

Every turn:
    if diced onions have been in a hot pan for ten turns:
        say "The onions are starting to look ready.";
        now the onions are sauteed.

Scorching Onions begins when Sauteeing Onions ends in disaster. Scorching Onions begins when the alone sauteed onions are in a hot container.

Scorching Onions ends horribly when the time since Scorching Onions began is three minutes. Scorching Onions ends in reprieve when the sauteed onions are not in a hot container. Scorching Onions ends in mixture when the sauteed onions are not alone.

When Scorching Onions ends in mixture:
    record "sauteeing onions" as achieved;
    say "The mixture of things in [the holder of the onions] stops them cooking quite so fast."

When Scorching Onions ends horribly:
    move smoke to Kitchen;
    now the onions are burnt.

When Scorching Onions ends in reprieve:
    record "sauteeing onions" as achieved;
    say "You've got the onions off heat before they can scorch -- a good sign."

Instead of taking the onions when the onions are in the pan: try taking the pan.

Instead of smelling in the presence of the smoke:
    say "The scent of the late disaster lingers in the air."

Reconstituting the Apricots is a scene.

Reconstituting the Apricots begins when the dried apricots are in a container which contains boiling water.

When Reconstituting the Apricots begins:
    say "The apricots slowly begin to plump up again."

Reconstituting the Apricots ends when the dried apricots are not in a container which contains boiling water.

Every turn:
    if dried apricots have been in a container which contains boiling water for ten turns:
        say "The apricots have turned plump(ish).";
        now the apricots are reconstituted;
        record "reconstituting apricots" as achieved.

Test sautee with "peel onions / cut onions / get onions / put onions in pan / get sage / wash sage / cut sage / wait / wait / wait / wait / wait / wait / wait / get pan".

Test apricots with "get kettle / open kettle / get apricots / put apricots in kettle / put kettle on stove / wait / wait / wait / wait / wait / wait / wait / wait / wait / wait / wait / wait / wait / wait / wait / wait / wait".

Test chicken with "open refrigerator / get chicken / open drawer / get mallet / hit breast".

Test cheese with "get scissors / get cheese / unwrap cheese".

Test me with "full score / test sautee / full score / test apricots / full score / test chicken / full score / test cheese / full score".

And... at that point you're a lot less close to being done than you think. The filling -- onions, sage, apricot, and cheese -- must be assembled and put in the chicken breasts; these tied up in string; each roll dipped in egg yolk and rolled in panko crumbs; these arranged in the Calphalon pan and baked. Then later, the whole retrieved from the oven, and the breasts transferred to a plate while we deglaze the pan and concoct the sauce with the chicken broth, wine, butter, etc. Then the chicken is sliced and plated, and the sauce poured over top. Usually one also wants a side dish or two. A number of things can go interestingly wrong in this process, of course, and implementing it would require, among other things, an intelligent management of all the possible mixtures that result.

442. Rubies ★★★

The trick here is that we need a table with text in order to keep track of the players' names.

Part 1 largely replicates the source from "Identity Theft"; new material starts at Part 2.

paste.png "Rubies"

Use scoring.

Part 1 - Collecting Names

The player's forename is a text that varies. The player's full name is a text that varies.

When play begins:
    now the command prompt is "What is your name? > ".

To decide whether collecting names:
    if the command prompt is "What is your name? > ", yes;
    no.

After reading a command when collecting names:
    if the number of words in the player's command is greater than 5:
        say "[paragraph break]Who are you, a member of the British royal family? No one has that many names. Let's try this again.";
        reject the player's command;
    now the player's full name is the player's command;
    now the player's forename is word number 1 in the player's command;
    now the command prompt is ">";
    say "Hi, [player's forename]!";
    say "[banner text]";
    move the player to the location;
    reject the player's command.

Instead of looking when collecting names: do nothing.

Rule for printing the banner text when collecting names: do nothing.

Rule for constructing the status line when collecting names: do nothing.

Part 2 - Adding the Leaderboard

File of Leaderboard is called "leaderboard".

When play begins:
    if the File of Leaderboard exists:
        read File of Leaderboard into the Table of Leaders;
        sort the Table of Leaders in reverse scored amount order.

When play ends:
    choose row 10 in the Table of Leaders; [we've sorted the table, so the lowest score will be the one at the bottom]
    if the score is greater than scored amount entry:
        now name entry is the player's forename;
        now the scored amount entry is the score;
    show leaderboard;
    write the File of Leaderboard from the Table of Leaders.

To show leaderboard:
    sort the Table of Leaders in reverse scored amount order;
    say "Current leading scores: [paragraph break]";
    say fixed letter spacing;
    repeat through Table of Leaders:
        if scored amount entry is greater than 0:
            say " [name entry]";
            let N be 25 minus the number of characters in name entry; [here we want to space out the scores so they make a neat column]
            if N is less than 1, now N is 1;
            say N spaces;
            say "[scored amount entry][line break]";
    say variable letter spacing.

To say (N - a number) spaces:
    repeat with index running from 1 to N:
        say " ".

Table of Leaders

scored amount

name

0

"Smithee"

0

"Smithee"

0

"Smithee"

0

"Smithee"

0

"Smithee"

0

"Smithee"

0

"Smithee"

0

"Smithee"

0

"Smithee"

0

"Smithee"

And now we introduce a scenario that allows different players to come up with different scores -- admittedly not a very interesting scenario, but it will do for now:

Part 3 - Scenario

Carry out taking something which is not handled:
    increment score.

The Big Treasure Chamber is a room. It contains a ruby, an emerald, a gold tooth, an antique katana, and a silver coin.

Instead of waiting, end the story finally.

Test me with "get ruby / z".

RB §11.5. Settings and Status Checks During Play

Several default actions allow the player some control over the presentation of the story, or permit the player to request information about what is going on. In addition to the standard commands described elsewhere in this section (SCORE, SAVE, UNDO, QUIT, RESTART, and RESTORE), Inform has the following actions that control the player's experience:

Preferring abbreviated room descriptions (SUPERBRIEF)
Preferring unabbreviated room descriptions (VERBOSE)
Preferring sometimes abbreviated room descriptions (BRIEF)
Switching score notification on (NOTIFY ON)
Switching score notification off (NOTIFY OFF)

The first three of these allow the player to change the way rooms are described on first and subsequent versions; the last two, when used in a story that provides a score feature, toggle on and off reports such as "[Your score has just gone up by three points.]" These are discussed elsewhere in the Recipe Book (see cross-references below).

These provide immediate feedback about the status of the story file being played:

Verifying the story file (VERIFY)
Requesting the story file version (VERSION)
Requesting the pronoun meanings (PRONOUNS)

VERIFY examines checksums to make sure that the story file being run is intact and correct. This is less often an issue now than it was in the days when story files were distributed by highly corruptible floppy disk, but the command persists and is very occasionally useful. VERSION gives the full banner text associated with the story, including title, author, release number, IFID, and other bibliographical data; it follows this with a list of the included extensions.

PRONOUNS announces to the player what the story is currently understanding as the antecedents of "him", "her", "it", and "them". This is often useful during testing, but sometimes also during play.

The following allow the player (when supported by his interpreter) to create a log of play:

Switching the story transcript on (TRANSCRIPT ON)
Switching the story transcript off (TRANSCRIPT OFF)

It is rarely a good idea to change the default performance of such commands: they are often finicky and closely tied to the interpreter in which the story runs. Moreover, disabling the "version" command means that the story file is not able to display attribution information for Inform and any included extensions, in violation of their respective licenses.

See also

Looking for a way to set the story's verbosity level for the player
Scoring for a discussion of score notification
Testing for some examples of status-check commands created for alpha- or beta-testing of a story

RB §11.6. Ending The Story

Play can end in many ways, at the writer's discretion:

end the story;
end the story finally;
end the story saying "You have reached an impasse, a stalemate";
end the story finally saying "You have succeeded.";

The phrase "end the story" by itself will finish play, printing "*** The End ***". Using one of the phrases with "saying..." allows us to specify some other text with which to conclude. Including "finally" means that the player has earned access to AMUSING text and other notes, if any of these are provided.

We can eliminate the asterisked headline entirely by removing the rule that prints it, thus:

The print obituary headline rule is not listed in any rulebook.

The next step is to print the player's score and, if applicable, the rank he achieved. By default a story doesn't feature scoring, but the following use option will incorporate it:

Use scoring.

Then, if we want to allow a score but alter the way it is reported, we may remove or modify the print final score rule, as in

The print final score rule is not listed in any rulebook.

or perhaps something like

The chatty final score rule is listed instead of the print final score rule in for printing the player's obituary.

This is the chatty final score rule: say "Wow, you achieved a whole [score in words] point[s] out of a possible [maximum score in words]! I'm very proud of you. This was a triumph. I'm being so sincere right now."

What happens next is normally that the player is invited to RESTART, RESTORE (from a saved story), QUIT or UNDO the last command. The presence of the question can somewhat undercut a tragedy, and Battle of Ridgefield shows another way to go out.

If we do leave the question in, the text is formed by the Table of Final Question Options, which by default looks like this:

Table of Final Question Options

final question wording

only if victorious

topic

final response rule

final response activity

"RESTART"

false

"restart"

immediately restart the VM rule

--

"RESTORE a saved story"

false

"restore"

immediately restore saved story rule

--

"see some suggestions for AMUSING things to do"

true

"amusing"

--

amusing a victorious player

"QUIT"

false

"quit"

immediately quit rule

--

"UNDO the last command"

false

"undo"

immediately undo rule

--

Because this is a table, we may alter the behavior by changing entries or continuing the table. Finality shows how we might take out the option to UNDO the last command, for instance.

Using an ending phrase that includes "finally" tells Inform to include the options that are marked "only if victorious". One common use is to let the player read some special bit of additional text, perhaps describing easter eggs he might have missed in the story or presenting some authorial notes. Xerxes ★★ demonstrates a simple AMUSING command to read final information, while Jamaica 1688 shows how to add completely new elements to the list of options.

Old-school adventures expected their adventurers to die early and die often. Labyrinth of Ghosts ★★ shows how the residue of such past attempts can be preserved into subsequent attempts, using an external file. Big Sky Country ★★★ shows how a player can be resurrected by, let us say, some beneficent god, so that a player can even die more than once in the same attempt.

Examples

383. Jamaica 1688

The options offered to the player at the end of the game are listed in the Table of Final Question Options, which means that we can add to them simply by continuing the table; what's more, the table gives us the opportunity to create a "final response rule", a rule that the game should follow in order to parse the player's input at this point.

So, for instance, if we wanted the player to be allowed to ask for notes about any of the rooms, characters, or objects in a historical game:

paste.png "Jamaica 1688"

Use scoring.

Section 1 - Procedure

Table of Final Question Options (continued)

final question wording

only if victorious

topic

final response rule

final response activity

"REVEAL the inspiration for something or somewhere"

true

"reveal [any thing]"

investigate something rule

--

--

true

"reveal [any room]"

investigate something rule

--

This is the investigate something rule:
    repeat through the Table of Footnotey Stuff:
        if the player's command matches the topic entry:
            say "[revelation entry][paragraph break]";
            rule succeeds;
    say "I'm afraid I have no revelation to vouchsafe there."

Section 2 - Scenario

The Upper Deck is a room. Lucius is a man in the Upper Deck.

The maximum score is 501.

When play begins: now the score is 501; end the story finally.

Table of Footnotey Stuff

topic

revelation

"reveal [Lucius]"

"Lucius is based on a historical buccaneer who sailed with William Dampier. The original did carry a Greek New Testament, from which he read aloud when the men were stranded in the jungles near Panama."

"reveal [Upper Deck]"

"The Callisto is a simplified and tidied representation of a pirate sloop ca. 1688."

384. Finality

By default, Inform reminds the player that he has the option of typing UNDO after a story-ending action. This is generally good practice, especially for the sake of novice players who might not be aware of this possibility otherwise, and might be frustrated by a loss they could easily step back from.

Just occasionally, though, we may decide that the player does not deserve any such notification:

paste.png "Finality"

Cliff Edge is a room. "This narrow strip overlooks a gorge many hundreds of feet deep, at whose bottom is a river of molten lava. The walls of the gorge are lined with poison-tipped spikes. Furthermore, the birds that inhabit this valley spit balls of fire. Good thing you're safe up here."

The Table of Final Question Options determines what options are to be given to the player after the story ends. We can change what is mentioned there by altering the entries. (The example Jamaica 1688 explains this table in more detail, and demonstrates some other things that we might do with it.)

When play begins:
    choose row with a final response rule of immediately undo rule in the Table of Final Question Options;
    blank out the final question wording entry.

Instead of jumping:
    say "If you insist.";
    end the story.

And if we decided that we didn't want the player to be able to undo the command at all, we should add the use option

Use undo prevention.

Test me with "jump".

385. Battle of Ridgefield

Occasionally, a piece of IF is sufficiently serious that it feels bathetic to offer the player the usual restore-restart-undo-quit options at the end. The following would replace "*** You have died ***" with a centered epitaph, then quit the game when the player hits a key.

This example relies on a standard extension to avoid any fancy programming:

paste.png "Battle of Ridgefield"

Include Basic Screen Effects by Emily Short.

Ridgefield is a room.

Instead of doing something when the turn count is greater than 1: say "Alas, you no longer have the strength."; end the story.

Rule for printing the player's obituary:
    say paragraph break;
    center "In defense of American Independence";
    center "at the Battle of Ridgefield, April 27, 1777,";
    center "died Eight Patriots who were laid in this ground,";
    center "Companioned by Sixteen British Soldiers,";
    center "Living, their enemies,";
    center "Dying, their guests";
    say paragraph break;
    wait for any key;
    stop game abruptly;
    rule succeeds.

386. Xerxes ★★

Building a menu is moderately tedious, so we will rely on the standard menu extensions provided. Thus:

paste.png "Xerxes"

Include Basic Screen Effects by Emily Short. Include Menus by Emily Short.

Table of Amusing Matter

title

subtable

description

toggle

"Cult Revisions"

--

"Did you try... [paragraph break] banning the worship of Seth? [line break] of Dionysus? [line break] assigning all your priests to Re? [line break] assigning male priests to Cybele? [line break] assigning married priestesses to Hestia? [line break] identifying one god as another (e.g., Isis and Hecate)? [line break] identifying a mortal as a god (e.g., Alexander as Helios-Apollo)?"

--

"Military Revisions"

--

"Did you try... [paragraph break] allying a Greek city-state with the Persians? (try >MEDIZE) [line break] playing Athens as a land-based power?"

--

Rule for amusing a victorious player:
    now the current menu is the Table of Amusing Matter;
    now the current menu title is "Things to Try";
    carry out the displaying activity;
    clear the screen.

Omitting about a half million words from this rigorous and educational but nonetheless enthralling simulation of centuries of history, culture, and religion, we will skip directly to:

Athens is a room.

Use scoring.

Every turn:
    if the score is greater than 10000, end the story finally.

When play begins: now the score is 10001.

Test me with "z".

441. Labyrinth of Ghosts ★★

A tradition among Nethack-like computer games of the old school is that a player's death in a given place leaves a ghost behind to haunt subsequent players. Information about past lives is sometimes stored in a "bones file", and in this example we do exactly that, for a grievously unfair little dungeon.

To begin with, the labyrinth itself. We create a kind of value to remember possible means of death in these tunnels, and we assign a coordinate position in some grid to each location. (We do this because grid positions can safely be stored in tables saved out to external files, whereas room names cannot - they represent data which changes each time we amend the source.)

paste.png "Labyrinth of Ghosts"

Use scoring.

A demise is a kind of value. The demises are drowned, buried by a rockfall, pierced by an arrow and slain. The latest demise is a demise that varies.

A grid location is a kind of value. (1,19) specifies a grid location. A room has a grid location called coordinates.

The Gateway is a room. "For the foolhardy adventurer, the perilous labyrinth lies north, east or south." The coordinates are (6,6). The Tomb is east of the Gateway. The coordinates are (7,6). The Rockfall Cave is north of the Gateway. "This partly fallen cave may perhaps extend further north." The coordinates are (6,5). Instead of going north in the Rockfall Cave, have the player buried by a rockfall. The Archery Canyon is south of the Gateway. "No telling why this canyon is named after archery, but perhaps if you wait around you'll find out." The coordinates are (6,7). Instead of waiting in the Archery Canyon, have the player pierced by an arrow. The Rock Pool is east of the Tomb. The coordinates are (8,6). The cold mountain pool is in the Rock Pool. The cold pool is fixed in place. Instead of entering the cold mountain pool, have the player drowned.

Every turn when a random chance of 1 in 10 succeeds:
    say "A dwarf appears out of nowhere, and throws a nasty little knife.";
    have the player slain.

And as compensation for these hazards:

Some silver bars are in the Tomb. The emerald is in the Rock Pool. The platinum pyramid is in the Canyon.

Table of Point Values
item score

silver bars

3

platinum pyramid

10

emerald

4

Report taking an item listed in the Table of Point Values:
    increase the score by the score entry;
    blank out the whole row.

We are now ready for the actual undertaking. The Table of Ghostly Presences holds up to twenty death notices, and is initially blank. Deaths are sequentially numbered, and this number is stored in the sequence column.

Table of Ghostly Presences

haunted position

score at death

turns at death

manner of death

sequence

a grid location

a number

a number

a demise

a number

with 19 blank rows.

As the story file starts up, we look to see if a ghosts file already exists. If one does, we load up the Table of Ghostly Presences with it: and if not, as will be the case the first time the player explores, we leave the table blank. We sort the table so that it has earlier deaths (lower sequence numbers) first.

The File of Ghosts is called "ghosts".

When play begins:
    if the File of Ghosts exists, read File of Ghosts into the Table of Ghostly Presences;
    sort the Table of Ghostly Presences in sequence order.

How will ghosts manifest themselves? Because this is only a small example, we will simply tell the player that he senses something. If several ghosts are present in the same place, the most aggrieved (that is, the most recent) is sensed first...

After looking:
    repeat through the Table of Ghostly Presences in reverse sequence order:
        if the haunted position entry is the coordinates of the location, say "You sense the ghostly presence of an adventurer, [manner of death entry] with a score of [score at death entry] in [turns at death entry] turns."

(For instance, "You sense the ghostly presence of an adventurer, buried by a rockfall with a score of 10 in 5 turns.") That just leaves the rule for bumping off the player. When the Table is full, and there are already 20 ghosts, the one who died longest ago (with the lowest sequence count) is eliminated, and his row blanked out. (This will always be row 1 since we sorted the table in sequence order on reading it in.)

To have the player (sticky end - a demise):
    let the new sequence number be 0;
    repeat through the Table of Ghostly Presences:
        let S be the sequence entry;
        if S is greater than the new sequence number, let the new sequence number be S;
    increment the new sequence number;
    if the number of blank rows in the Table of Ghostly Presences is 0:
        choose row 1 in the Table of Ghostly Presences;
        blank out the whole row;
    choose a blank row in the Table of Ghostly Presences;
    now the sequence entry is the new sequence number;
    now the manner of death entry is the sticky end;
    now the turns at death entry is the turn count;
    now the score at death entry is the score;
    now the haunted position entry is the coordinates of the location;
    write the File of Ghosts from the Table of Ghostly Presences;
    now the latest demise is the sticky end;
    end the story saying "You have been [latest demise]".

Strictly speaking we ought to worry that after 2,147,483,647 deaths, the sequence numbers would grow too large to store in a single value, and then the sequence of ghosts will be erratic. But it seems unlikely that anyone will play this example 2.1 billion times.

138. Big Sky Country ★★★

Some older games allowed the player to be resurrected after a death, but punished him by distributing his possessions far and wide. Here we emulate that effect.

paste.png "Big Sky Country"

Use scoring.

When play begins: say "There's a bit of a drive over from Anaconda, Montana, and then through a couple or three ghost towns, but finally you find what you're looking for, and strike out on foot..."

Entrance to Devil's Canyon is a room. "You are at the top of a steep road, which proceeds down into the canyon proper." A sign is in Devil's Canyon. It is fixed in place. "An ominous sign has been put up by the local sheriff's office." The description is "PROCEED AT OWN RISK - NO RESCUES!"

Instead of going down when a random chance of 1 in 3 succeeds:
    say "Whoooops, your footing is not as secure as you thought...";
    end the story.

Dusty Path is below Entrance. "A dusty path, with grey-brown thorny bushes on either side. Immediately to your right is a sheer drop; far below you can see the rusting remains of a Model T that some fool tried to drive by here."

Hairpin is below Dusty Path. "A sharp bend in the road, doubling back down towards the bottom of the canyon. Just north of here there is also a small cavern of some kind[if the stick pin is in the cavern], which attracts your eye with some glittery thing[end if]."

The Cavern is north of Hairpin. "Really not much more than a little hollow in the side of the canyon." In the cavern are a snake and a diamond stick pin. The snake is an animal. The description of the snake is "You're no expert, but it looks like a rattler."

Instead of taking the diamond stick pin in the presence of the snake: say "Turns out the snake is partial to that there pin, and takes exception to your intending to make off with it."; end the story.

In a fuller implementation of this game, we might make it possible to get by the snake, but in this version, it's just going to remain troublesome.

Crooked Path is below Hairpin. "You're about two thirds of the way down to the bottom of the cavern at this point."

At the Spot is below Crooked Path. "This'll be it: a bare patch of ground that might as well have an X painted right on it."

Rule for supplying a missing noun while digging:
    now noun is the location.

Understand "dig" or "dig hole/here" or "dig in ground/dirt/earth" as digging. Digging is an action applying to one thing.

Instead of digging at the spot:
    say "You dig and dig, and after a half hour or so, sure enough, you do turn up a big box of gold! You're going to be richer than God and Bill Gates put together.";
    increase the score by 5;
    end the story finally.

Instead of digging at the spot when the player does not carry the shovel:
    say "What, without your shovel? That won't work too well."

The player carries a walking stick. The player wears a hat, a whistle, and a daypack. The daypack contains a mylar blanket, a granola bar, a cellular phone, a water bottle, a folding shovel, and a photocopied map. The granola bar is edible. Instead of drinking the water, say "You quench your thirst, for the time being." The description of the map is "The map shows the winding path of Devil's Canyon, with a large X down by the south end. That would be where your uncle Jesse buried the gold from the train robbery."

The maximum score is 5.

When play ends when the story has not ended finally:
    say "Oh dear, that ought to be fatal! However, if you like I can get you out of it...

    Shall I? >";
    if the player consents:
        repeat with item running through things had by the player:
            move the item to a random visited room;
        say "A strong wind picks you up and sets you back at [the location], though perhaps minus a few of your things.";
        resume the story;
        try looking.

"If the player consents" is just a convenient way to ask a yes/no question that the player must answer before going on with the game.