Inform 7 Home Page / Documentation
§12.7. New actions
It is not often that we need to create new actions, but a large work of interactive fiction with no novelty actions is a flavourless dish. Here we shall create an action for photographing things.
The Ruins is a room. "You find this clearing in the rainforest oddly familiar." The camera is in the Ruins. "Your elephantine camera hangs from a convenient branch."
Photographing is an action applying to one visible thing and requiring light.
In theory that text is already sufficient to make the new action, but what we have so far is rudimentary to say the least. The two qualifications give Inform the useful information that we cannot photograph in the dark, and that we need to be photographing something - not, as in the case of waiting or taking inventory, acting without reference to any particular thing external to ourselves.
The word "visible" here tells Inform that we do not need to be able to touch the thing in question: a line of sight is good enough. These two stipulations were necessary because the default arrangement is that any object must be in touching range, and that most actions can be performed in darkness. (Also, note that if you invent an action which needs to apply to directions like "north" or "south", you need to make this apply to visible things, because the object used inside Inform to represent the idea of "north" can be seen but not touched. So for understanding purposes, "visible thing" is understood as meaning any visible thing or direction: it's more general than "thing", not more specific.)
Occasionally, when writing general rules about actions, it can be useful to find out what the current action's requirements are: the following conditions do what they suggest.
if action requires a touchable noun:
This condition is true if the action being processed is one whose (first) noun is an object which needs to be touchable by the actor. For example, it's true for "taking", but false for "examining".
if action requires a touchable second noun:
This condition is true if the action being processed is one whose second noun is an object which needs to be touchable by the actor. For example, it's true for "putting the brick in the sack", but false for "throwing the brick at the window".
if action requires a carried noun:
This condition is true if the action being processed is one whose (first) noun is an object which needs to be carried by the actor. For example, it's true for "dropping", but false for "taking".
if action requires a carried second noun:
This condition is true if the action being processed is one whose second noun is an object which needs to be carried by the actor.
if action requires light:
This condition is true if the action being processed is one which can only be performed if the actor has light to see by. For example, it's true for "examining", but false for "dropping".
As further examples, here we create "blinking" and "scraping X with Y". Note the use of "it" to indicate that the name of an object should go here.
Blinking is an action applying to nothing. Scraping it with is an action applying to two things.
The photographing action now exists, but with two provisos: (a) it never happens, because Inform does not know what commands by the player should cause it, and (b) even if it were to happen, nothing would follow, because Inform does not know what to do. (There are no check, carry out or report rules yet.)
The first problem is easily overcome:
Understand "photograph [something]" as photographing.
We will return to the whole subject of parsing, as this process of understanding the player's commands is called, later. But this gives the gist of it.
See Understand for the full story
|Start of Chapter 12: Advanced Actions|
|Back to §12.6. Spontaneous actions by other people|
|Onward to §12.8. Irregular English verbs|
Suppose we have some items that get wet in contact with other damp things; in particular, if we touch anything wet while wearing a pair of gloves, the gloves too get damp. This requires that we be systematic about detecting all cases where contact occurs. So:
A liquid distribution rule:
repeat with item running through containers:
if the item is open and the item is empty and the item is in a waterfilled container:
now the item is waterfilled;
if the player can see the item, say "[The item] fills up with water, of course.".
A liquid distribution rule:
repeat with item running through things in a waterfilled container:
if the item is porous and the item is dry:
if the player can see the item, say "[The item] soaks through.";
now the item is sodden.
The copy of The Last Man is a book. The description of The Last Man is "Mary Shelley's very own original copy, loaned to you under the strictest of agreements[if the pond encloses the copy]. How it came to be in its present position is a long story, and not important at the moment: the critical thing is not to blame oneself - who could have anticipated the cricket bat, anyway? - but to fix it immediately, before anything worse occurs[end if]." The The Last Man is in the ziploc bag. The ziploc bag is waterproof and empty. It is openable, transparent, and closed.
The Back Garden is a room. The Back Garden contains a pond. The pond is a waterfilled container. In the pond is the ziploc bag. A carp is in the pond. The carp is an animal. Instead of taking the carp, say "You're not fast enough."
Rule for writing a paragraph about the pond:
if the pond encloses the Last Man:
say "It is a beautiful day just at the end of spring and beginning of summer. The sun shines, the trees blossom, the world conspires in Edenic cheerfulness. You can take in none of it. Your eye is on [the Last Man].";
say "The pond[if something is in the pond] (containing [the list of things in the pond])[end if] remains a figure of menace in an otherwise lushly verdant landscape."
After printing the name of something (called the target) while writing a paragraph about something:
if the Last Man is enclosed by the Pond:
if the target is in something (called the parent), say " - which is in [the parent]".
The Kitchen is west of the Back Garden. "Not in any sense your province: Mrs Peaswell gets agitated if anyone besides herself so much as boils a kettle. In general it is best to sneak through, disturbing as little as possible and preserving the cosy domestic fiction that academics cannot cook.
The Stairwell is above the Kitchen. "Halfway up and halfway down." The airing cupboard is a container in the Stairwell. "An airing cupboard here contains the heating system, and is the ideal place for restoring wet items to a dry state." The airing cupboard is fixed in place.
Now: whenever the player definitely touches something, we want to follow certain rules about the transfer of liquid. These rules need to come after an action's check rules (to make sure the action really occurs) and before the carry out rules (so that nothing has moved or changed yet). So we'll borrow from the chapter on rulebooks to create a whole new stage to the action, occurring between the check and the carry out phases:
A post-check rule (this is the dry glove rule):
if we get wet:
if the player wears the gloves and the gloves are dry:
now the gloves are sodden;
say "(soaking your gloves in the process)";
continue the action.
A post-check rule (this is the wet glove rule):
if the player wears the sodden gloves:
if the The Last Man must be touched and the Last Man is not sodden:
say "(soaking the parched pages of The Last Man with the rude touch of your sodden gloves)";
now the The Last Man is sodden;
continue the action.
Before doing something when the player does not wear the gloves:
if The Last Man must be touched:
if The Last Man is dry, say "[The The Last Man] is too precious to endanger when you are not wearing gloves." instead;
otherwise say "You hesitate instinctively, then recollect that you can hardly harm [The The Last Man] any more than it has already been harmed...".
To decide whether (item - a thing) must be touched:
if the item is the noun and the action requires a touchable noun, yes;
if the item is the second noun and the action requires a touchable second noun, yes;
The box of enrobed cakes is in the Wawa. "A box of Tastykake Enrobed Cakes has fallen off its shelf." The description is "'Enrobed Cakes' is a fancy term for 'strange sponge-like baked good, covered in a thin shell of waxy chocolate'. They are addictive, but not in a way that lets you respect yourself in the morning." The box is a closed openable container. In the box is a cake.
Because the can of root beer should have some reactions to having been shaken later in the game, we need to borrow a few ideas from the chapter on Time:
Instead of opening the agitated can of root beer:
now the can of root beer is nowhere;
now the sticky mess is in the location;
say "You open the can and fizzing sweet soda goes absolutely everywhere."