12.20. Stored actions

| Chapter 12: Advanced Actions |

| 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 "stored action" which can do all of this automatically. As with most other kinds of value, stored actions can be held in variables, "let" values, properties or table columns. For example:

> The best idea yet is a stored action that varies.

creates a variable called "the best idea yet" which holds a stored action.

This will normally be created holding the default value - the player waiting. We really only have two ways to make more interesting stored actions:

action of (an action) ... stored action

This phrase produces a literally typed action as a value. Example: now the best idea yet is the action of pushing the button; The action must be specific in every respect, so "action of taking something" or "action of doing something" will not work - "taking something" is really a general description of many possible actions, not an action in its own right.

Note the words "action of...", which convert any sufficiently exact description of an action into its stored action form.

current action ... stored 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 arising 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 stored 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.

try (stored action)

This phrase makes the stored action take effect now. Example: try the present whim; If the present whim contains, say, the action of taking the beach ball, then the effect is exactly the same as "try taking the beach ball". The stored action isn't destroyed or otherwise used up in the process, so it can be tried again another time, as often as we like.

silently try (stored action)
or: try silently (stored action)

This phrase makes the stored action take effect now, under the "silent" convention which means that routine messages aren't printed. Example: silently try the present whim; If the present whim contains, say, the action of taking the beach ball, and the action succeeds, nothing is printed, but if something goes awry then a message is printed to say why. Either way, the effect is exactly the same as "try silently taking the beach ball".

But stored 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. Now, it would not make sense to write

> if the best idea yet is the action of taking something, ...

because "action of ..." has to make an exact action, which clearly this is not: so Inform will produce a problem message if we try. But we do not need to, because Inform also allows us to compare a stored action against any description of an action, however vague:

> if the best idea yet is taking something, ...
> 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.

When dealing with stored actions, we sometimes want to know what they are dealing with. We can extract this information using the following phrases:

action name part of (stored 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

noun part of (stored 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 (stored 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 (stored 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 (stored 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".

219
| Example Bosch 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. |
RB

220
| Example Cactus Will Outlive Us All For every character besides the player, there is an action that will cause that character to wither right up and die. |
RB

221
| Example Actor's Studio A video camera that records actions performed in its presence, and plays them back with time-stamps. |
RB

222
| Example Anteaters 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". |
RB

Previous | Contents | Next