§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. Something else to be aware of is that the terms "actor", "noun" and so on will refer to that stored 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 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 action

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".


arrow-up.pngStart of Chapter 12: Advanced Actions
arrow-left.pngBack to §12.19. Changing visibility
arrow-right.pngOnward 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:

paste.png "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.

*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:

paste.png "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.

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:

paste.png "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.

*ExampleCactus 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.

**ExampleActor's Studio
A video camera that records actions performed in its presence, and plays them back with time-stamps.

**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".