12.10. Action variables

| Chapter 12: Advanced Actions |

| 12.10. Action variables

For some complex situations, it can be useful to keep track of a few values throughout the processing of the action. This is not an everyday occurrence: in the Standard Rules, for instance, only two or three out of 90 actions need to do this. But suppose we want to write a more deluxe version of our "photographing" action. This time, rather than having a single thing called the "camera", we will provide a whole range of possible cameras, varying in quality:

> Photographing is an action applying to one visible thing and requiring light. Understand "photograph [something]" as photographing.

> The Studio is a room. Sally is a woman in the Studio. A foam-lined tote bag is in the Studio.

> A camera is a kind of thing. A camera has a number called picture quality. The digital SLR camera is a camera in the tote bag. The player carries a camera called the instant one-shot camera. The picture quality of the SLR camera is 10. The picture quality of the one-shot is 2. Definition: a camera is sharp if its picture quality is 5 or more.

And we will want the photographing action to have the player use the best-quality camera which comes to hand. We will give the action a variable called the 'camera photographed with', thus:

> The photographing action has an object called the camera photographed with.

Every action's variables must be named differently from those of all other actions, because there are some "before" rules (for instance) which take effect for many different actions, and which might need access to any of their variables. So action variables should be named in a way marking out to which action they belong. The best way to do this is to include the past participle of the action name - just as "camera photographed with" contains the past participle "photographed" of the action "photographing".

This value is created when the action begins, and disappears when the action ends. (If the action should happen a second time before the first time was completed, a second copy of the value is created, leaving the original undisturbed.) When the action begins, the value starts out as something neutral - so if it is a number, it starts out as 0, if a text, it starts out as the blank text "", and so on. Here it is an object, so it starts out as nothing - the value meaning no object at all. But of course we want to give it a value ourselves. We can do that using the "setting action variables" rulebook. For instance:

> Setting action variables for photographing:
> now the camera photographed with is the sharpest camera which is carried by the actor.

The "setting action variables" rulebook is run through before even the before rules, and it has no power to stop or change the action. Its rules should say nothing and do nothing other than to set rulebook variables like this one. Note that it is intended to work for any actor, not only the player: so rather than referring to the player as the performer of the action, we need to write "the actor", as in the example above. (See subsequent sections for more on actors.)

We can now write rules such as:

> A check photographing rule:
> if the camera photographed with is nothing:
> say "You can hardly photograph without a camera, now can you?" instead.

Only rules to do with the photographing action - before, instead, after, check, carry out, or report rules, and so on - are allowed to see the 'camera photographed with' value: it's the private property of the action.

A further elaboration allows us to make rules about photographing neater to write. If we create our variable like so:

> The photographing action has an object called the camera photographed with (matched as "using").

...then we are now allowed to add an optional 'using ...' clause onto a description of the action. The clause has to be introduced with a single word: here, it's 'using'. For instance, we could write rules such as

> Instead of photographing something using the one-shot camera:
> say "But you promised to give this to Sally's nephew."

> Check photographing something using the noun:
> say "That would require some sort of contraption with mirrors." instead.

> Report photographing something using a sharp camera:
> say "You feel cool and important as the shutter clicks."

(This is the method used by the Standard Rules to attach optional clauses such as 'to', 'with' and 'through' to the going action.)

198
| Example Further Reasons Why All Poets Are Liars The young William Wordsworth, pushing a box about in his room, must struggle to achieve a Romantic point of view. |
RB

199
| Example The Second Oldest Problem Adapting the going action so that something special can happen when going from a dark room to another dark room. |
RB

200
| Example Removal TAKE expanded to give responses such as "You take the book from the shelf." or "You pick up the toy from the ground." |
RB

201
| Example Puff of Orange Smoke A system in which every character has a body, which is left behind when the person dies; attempts to do something to the body are redirected to the person while the person is alive. |
RB

Suppose we want to let the player kill characters, leaving behind corpses. "Puff of Orange Smoke" Paraguay is a room. Bolivia is north of Paraguay. Lydia is a woman in Paraguay. "Lydia is, as usual, here." The description of Lydia is "Long, long legs and a sarcastic attitude." Instead of touching Lydia: say "'Watch it, sailor,' she snaps." A body is a kind of thing. A body is a part of every person. Instead of touching a body: say "[The noun] is grotesquely inert." The description of Lydia's body is "Long, long legs and no attitude at all." The initial appearance of Lydia's body is "Lydia's corpse is sprawled at your feet." Using our "part of every person..." line, we've conveniently assigned one body per person. Since we're going to separate people from their bodies when the bodies die, though, we also want a more permanent relation that will help us keep track of which bodies used to belong to which people: Spirit-possession relates one person to one body. The verb to be owner of implies the spirit-possession relation. When play begins: repeat with victim running through people: let the corpse be a random body which is part of the victim; now the victim is owner of the corpse. When Lydia is alive, we want >TOUCH LYDIA'S BODY to mean the same thing as >TOUCH LYDIA, so we use the setting action variables rules as a convenient point at which to reassign the action: Setting action variables when the noun is a body which is part of a person (called owner): now the noun is the owner. Setting action variables when the second noun is a body which is part of a person (called owner): now the second noun is the owner. This doesn't change Inform's idea about what action is being performed; just about the object it's being performed on. The rest of the action will now proceed as if the player had typed >TOUCH LYDIA. Along similar lines, once Lydia is dead, we want >MOVE LYDIA to mean >MOVE LYDIA'S BODY if the body is in view: Setting action variables when the noun is a dead person and the noun is owner of a visible body (called the mortal remains): now the noun is the mortal remains. The trick is, though, that >MOVE LYDIA will only be understood if there is something called Lydia that the player can see and refer to, even after she's dead. There are various ways to do this, but the least painful here will be to make the deceased Lydia permanently visible, by putting her in an always-accessible backdrop. The backdrop itself will never be mentioned in the game, and we should make its name something that the player is unlikely to type casually; we don't want the player to interact with it directly. So: The worldview is a privately-named backdrop. It is everywhere. The spirit-world is a privately-named transparent closed unopenable container. It is part of the worldview. Definition: a person is dead if he is in the spirit-world. It's also possible that the player will type something like >X LYDIA when Lydia's corpse is not in view, so we should have an appropriate answer to that as well: Before doing something to a dead person: say "[The noun] is dead; or had you blocked that out?" instead. Because the before rules happen after the setting action variables rules, this will only ever happen if the corpse is not visible. Now we define the attack itself, which should discard the body, move the spirit to its eternal resting place, and describe the event to the player: Instead of attacking someone: let the corpse be a random body which is part of the noun; move the corpse to the location; move the noun to the spirit-world; say "With a single blow, you rid the world of [the noun]." And finally a trick borrowed from the chapter on understanding, so that we can refer to "Lydia's body" while Lydia is alive, but "Lydia's corpse" only after Lydia has died: Understand "corpse" as a body when the item described is not part of a person. Test me with "x body / x lydia's body / touch lydia's body / x corpse / kill lydia / look / x lydia's body / x lydia's corpse / x corpse / x lydia / touch lydia / lydia, hello / n / x lydia / touch lydia / lydia, hello".

202
| Example Croft Adding special reporting and handling for objects dropped when the player is on a supporter, and special entering rules for moving from one supporter to another. |
RB

Previous | Contents | Next