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:
"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.
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:
"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".
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:
"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."
|
Building a menu is moderately tedious, so we will rely on the standard menu extensions provided. Thus:
"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".
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.)
"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.
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.
"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.