Chapter 11: Out Of World Actions and Effects
§11.1. Start-Up Features; §11.2. Saving and Undoing; §11.3. Helping and Hinting; §11.4. Scoring; §11.5. Settings and Status Checks During Play; §11.6. Ending The Story
![]() | Contents of The Inform Recipe Book |
![]() | Chapter 10: Physics: Substances, Ropes, Energy and Weight |
![]() | Chapter 12: Typography, Layout, and Multimedia Effects |
![]() | Indexes of the examples |
§11.1. Start-Up Features
When the story file starts up, it normally 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 Map for a way to generate a randomized maze at the start of play
See Food for a way to choose a random piece of candy to be poisonous
See Getting Acquainted for a way to choose a murderer from among the characters at the start of each game
![]() | Start of Chapter 11: Out Of World Actions and Effects |
![]() | Back to Chapter 10: Physics: Substances, Ropes, Energy and Weight: §10.11. Mathematics |
![]() | Onward to §11.2. Saving and Undoing |
|
|
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:
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:
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:
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. |
|
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:
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:
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:
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. |