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:
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
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
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
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
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:
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:
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.
|Start of Chapter 12: Advanced Actions|
|Back to §12.19. Changing visibility|
|Onward to §12.21. Guidelines on how to write rules about actions|
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:
taking the emerald leaf
eating the gilded lily
(And our list would presumably continue from there, in the full game.)
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.
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.
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
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:
Here we construct a video camera to track and play back actions:
with 25 blank rows.
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;
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.
Notice that both Lucas' implied taking action (picking up the croissant) and his eating action are recorded on the same move.
"You flip through the Guide for a while and eventually realise that spines are flora, not fauna."
"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."
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.