Inform 7 Home Page / Documentation
§12.20. Stored actions
As we have seen, to describe an action fully takes a complicated little bundle of information - we need to know what is to be done, who will do it, and what it will be done to. There are times when we would like to remember an action and look back on it later (perhaps many turns later, after many other actions have taken effect) - but this is not easy to do with only the techniques we have seen so far. There are quite a few cases to get right, and it would be easy to not store quite enough of the details.
Fortunately, Inform provides a kind of value called "action" which can do all of this automatically. (In older versions of Inform this was called "stored action", but the word "stored" is now unnecessary, and makes no difference.) As with most other kinds of value, actions can be held in variables, "let" values, properties or table columns. For example:
The best idea yet is an action that varies.
creates a variable called "the best idea yet" which holds an action.
This will normally be created holding the default value - the player waiting. We really only have two ways to make more interesting actions. One is by typing them out explicitly, like so:
now the best idea yet is pushing the button;
Here "pushing the button" is a constant of the kind "action", so it goes into happily into "best idea yet" in the same way that a number like 3 could go into a number that varies. The action must be specific in every respect, so "taking something" or "doing something" will not work - "taking something" is really a general description of many possible actions, not an action in its own right.
The other way to produce a useful action is:
current action ... action
This phrase produces the action currently being processed as a value - it literally stores the action, and remembers, if necessary, the exact wording of the player's command at the time it was stored - so that even actions ari ing from commands like LOOK UP X100 IN THE CODE BOOK can be stored faithfully. Examples:
let the present whim be the current action;
say "How you would like to be [current action].";
This only makes sense if an action is currently going on, so it shouldn't be used in "every turn" rules, for instance.
So much for making actions: now for making use of them. The first obvious idea is to store up an action for several turns and then have it take effect later. That's easily done: just as we can "try" any action written out explicitly, so we can also try a stored one. The phrase to do this has exactly the same wording either way, since it does the same thing either way.
But actions can still be useful even if we never intend to try them. For one thing, we can say them, and this produces a fairly natural description of what the action is:
Before doing something in the presence of the bearded psychiatrist: say "'Zo, the subject vishes to engage in [the current action]. Zis is very interesting.'"
will produce text such as:
"So, the subject vishes to engage in rubbing the fireman's pole. Zis is very interesting."
One of Inform's most convenient features is its ability to test if the action being processed matches vague or complicated descriptions of whole classes of actions. For example,
if the best idea yet is taking something, ...
works even though "taking something" is not a single action; it's a description which could apply to many different actions (taking a box, taking a ball, and so on). What Inform tests is whether the "best idea yet" value, a single action, fits this description or not. We can be even vaguer:
if the best idea yet is doing something to the lever, ...
Just occasionally, this can lead to ambiguities. For instance,
if the current action is wearing something, ...
fails because Inform thinks "wearing" is meant in the sense of the current action having clothes on, so it produces a problem message. To avoid this, simply write:
if the current action is trying wearing something, ...
which can't be misunderstood. Something else to be aware of is that the terms "actor", "noun" and so on will refer to that action: for instance, in
if the best idea yet is taking the noun, ...
"noun" here refers to the noun in "best idea yet", not to its meaning outside of this phrase (if indeed it has such a meaning).
When dealing with actions, we sometimes want to know what they are dealing with. We can extract this information using the following phrases:
action name part of (action) ... action name
This phrase produces the action name part of an action. Example: suppose the current actor is Algy, who is throwing the brick at Biggles. Then
action name part of the current action = throwing it at action
noun part of (action) ... object
This phrase produces the (first) noun of an action. Example: suppose the current actor is Algy, who is throwing the brick at Biggles. Then
noun part of the current action = the brick
If the noun is something other than an object, this produces just "nothing", the non-object.
second noun part of (action) ... object
This phrase produces the second noun of an action. Example: suppose the current actor is Algy, who is throwing the brick at Biggles. Then
second noun part of the current action = Biggles
If the second noun is something other than an object (for instance for the command SET DIAL TO 3417 it would be the number 3417), this produces just "nothing", the non-object.
actor part of (action) ... object
This phrase produces the person who would be carrying out the action if it were being tried. Example: suppose the current actor is Algy, who is throwing the brick at Biggles. Then
actor part of the current action = Algy
The following phrase is a convenient shorthand form:
if (action) involves (object):
This condition is true if the object appears as any of the actor, the noun or the second noun in the action. Example:
if the current action involves Algy
would be true for "give revolver to Algy", "Algy trying flying the Sopwith Camel", "examine Algy" and so on, but false for "ask Raymond about secret airfield".
action of (an action) ... action
This phrase is now seldom needed. It produces a literally typed action as a value. Example:
now the best idea yet is the action of pushing the button;
Nowadays in most contexts we can just type "pushing the button" as a value, and that will work fine, so this phrase is retained only to keep old code working.
|
ExampleBosch
Creating a list of actions that will earn the player points, and using this both to change the score and to give FULL SCORE reports.
|
|
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:
"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.
"Cactus Will Outlive Us All"
Death Valley is a room. Luckless Luke and Dead-Eye Pete are men in the Valley. A cactus is in the Valley. Persuasion rule: persuasion succeeds.
A person has an action called death knell. The death knell of Luckless Luke is pulling the cactus. The death knell of Dead-Eye Pete is Luke trying dropping the cactus.
Before an actor doing something:
repeat with the victim running through people in the location:
let the DK be the death knell of the victim;
if the DK is not waiting and the current action is the DK:
say "It looks as if [the DK] was the death knell for [the victim], who looks startled, then nonexistent.";
now the victim is nowhere.
If we leave it at that, then pulling the cactus will kill Luckless Luke but then say "Nothing obvious happens.", which seems like a bit of an anti-climax. So we add a special case response for that one:
After pulling the cactus when Luckless Luke was in the location:
say "That's a real shame."
Test me with "get cactus / drop cactus / luke, get cactus / luke, drop cactus / pull cactus / look".
|
ExampleActor's Studio
A video camera that records actions performed in its presence, and plays them back with time-stamps.
|
|
Here we construct a video camera to track and play back actions:
"The Actor's Studio"
Section 1 - The Video Camera
The video camera is a thing carried by the player.
Table of Videotape
recorded action
|
time stamp
|
waiting
|
9:00 AM
|
with 25 blank rows.
|
Mode is a kind of value. The modes are idle, recording, and playing back. The video camera has a mode. The video camera is idle.
Understand "play back" as playing back. Instead of switching on the camera, try tuning the camera to recording. Instead of switching off the camera, try tuning the camera to idle.
The description of the video camera is "It is currently [mode]; its available settings are idle, recording, and playing back."
Understand "set [camera] to [a mode]" as tuning it to. Tuning it to is an action applying to one thing and one mode.
Instead of setting the camera to something:
say "The available settings are idle, recording, and playing back."
Check tuning it to:
if the noun is not the camera, say "Only the video camera can be set to [the mode understood]." instead.
Carry out tuning it to:
now the mode of the noun is the mode understood.
Report tuning it to:
say "You set [the noun] to [mode understood]."
After an actor doing something when the video camera is recording:
if the current action is tuning the video camera to recording, make no decision;
if the number of blank rows in the Table of Videotape is greater than zero:
choose a blank row in the Table of Videotape;
now the recorded action entry is the current action;
now the time stamp entry is the time of day;
otherwise:
now the video camera is idle;
say "The video camera runs out of recording memory and switches off.";
continue the action.
Every turn when the video camera is playing back:
say "On the camera screen, you see [run paragraph on]";
let starting playback be false;
repeat through the Table of Videotape:
if the recorded action entry is not waiting:
now starting playback is true;
say "[line break] -- [if the actor part of the recorded action entry is the player]you [end if][the recorded action entry], time stamped at [time stamp entry]";
blank out the whole row;
if starting playback is false, say "only static.";
otherwise say paragraph break.
Section 2 - The Scenario
The Actor's Studio is a room. Lucas is a man in the Actor's Studio. Persuasion rule: persuasion succeeds.
The Studio contains an edible thing called a croissant.
Test me with "set camera to recording / x lucas / lucas, take inventory / lucas, eat croissant / set camera to playing back / z".
Notice that both Lucas' implied taking action (picking up the croissant) and his eating action are recorded on the same move.
|
ExampleAnteaters
The player carries a gizmo that is able to record actions performed by the player, then force him to repeat them when the gizmo is dropped. This includes storing actions that apply to topics, as in "look up anteater colonies in the guide".
|
|
"Anteaters"
A book is a kind of thing. Understand "book" as a book. A book has a table name called the contents.
Report consulting a book about:
say "You flip through [the noun], but find no reference to [the topic understood]." instead.
Instead of consulting a book about a topic listed in the contents of the noun:
say "[reply entry][paragraph break]".
The Guide to Desert Fauna is a book. The contents of the Guide is the Table of Critters.
Table of Critters
topic
|
reply
|
"spines"
|
"You flip through the Guide for a while and eventually realise that spines are flora, not fauna."
|
"anteater colonies"
|
"The giant anteater, which grows to six feet in size and can kill a jaguar, is a solitary animal, found in many habitats, including grasslands, deciduous forests and rainforests. It does not form colonies. That's ants. They're actually quite easy to tell apart."
|
Death Valley is a room. The Guide is in the Valley.
The gizmo is in Death Valley. The gizmo has an action called idea. The description of the gizmo is "The gizmo is hard to describe, but it projects an idea of [idea]."
Before when the player carries the gizmo and the idea of the gizmo is waiting:
say "[The gizmo] eagerly soaks up the whole idea of [the current action].";
now the idea of the gizmo is the current action.
After dropping the gizmo:
say "The percussion of the fall seems to have shaken the gizmo's idea loose! There's nothing for it now but [idea of the gizmo].";
try the idea of the gizmo;
now the idea of the gizmo is waiting.
Test me with "get guide / look up spines in guide / x gizmo / get gizmo / i / x gizmo / drop gizmo / get gizmo / look up anteater colonies in guide / x gizmo / drop gizmo".