Chapter 17: Activities
17.5. New activities

Activities are all about influencing the standard mechanisms which Inform uses, so it might at first seem that there is no need to create new activities: but on further reflection, quite a lot of the writing of interactive fiction involves creating new and systematic ways to do things, and as soon as we have a general rule, we will want to have exceptions. Inform therefore allows us to create our own activities, giving us ways to influence the operation of our own mechanisms.

There are two kinds of activity: those which relate to a specific thing or room, and those which do not. The following creates one of each kind:

Analysing something is an activity.
Assaying is an activity.

Here "analysing something" relates to a specific item: Inform knows this because it looks for the clue "something" (or "of something") after the activity's name, which in the first case above is simply "analysing".

Creating an activity is like creating an action: it automatically makes new rulebooks - "before analysing", "for analysing" and "after analysing" - but they start out empty, so the activity does nothing yet. Moreover, it never happens. We can make an activity happen at any time by writing phrases like so:

carry out the analysing activity with the pitchblende;
carry out the assaying activity;

To make the activity do something useful, we need to put a rule into its "for" rulebook:

The last for assaying rule:
    say "Professionally, you cast an eye around mineral deposits nearby, noticing [list of rocks in the location]."

"The last" is a technicality about rulebooks (see the next chapter) which, put briefly, guarantees that this rule comes last among all possible "for assaying" rules. This is good form because the whole point of an activity is to make it easy for further rules to interfere - so we deliberately hang back to last place, giving precedence to anybody else who wants it.

It may look rather pretentious to dress up the footling little "assaying" example as an activity, but it gains us more than might first appear. Every new activity created provides a context which other activities can observe. We could, for instance, define

Rule for printing the name of a rock while assaying: ...

so that during assays more technical names are used.


294
** Example  AARP-Gnosis
An Encyclopedia set which treats volumes in the same place as a single object, but can also be split up.

RB
295
*** Example  Aftershock
Modifying the rules for examining a device so that all devices have some specific behavior when switched on, which is described at various times.

RB
296
*** Example  Crusoe
Adding a "printing the description of something" activity.

RB

Suppose we want to add rules so that any time we examine a charred object (and most of our objects can be charred), a line about the charring is appended to the end of the object description. We could use "after examining...", but perhaps we would prefer for the sentence about the charring not to appear in its own paragraph.

This is an ideal occasion for a new activity. We look at the action index for "examining" to identify the rule that causes the old behavior (in this case, the "standard examining rule"); replace this with a new rule that calls our activity; and write our "printing the description" activity in such a way that it uses an object's description without forcing a paragraph return afterward.

Then we will use "after printing the description" to add our line about charring, and make sure that the paragraph return does occur before the prompt.

So:

"Crusoe"

Section 1 - Creating our New Activity

The fancy examining rule is listed instead of the standard examining rule in the carry out examining rules.

This instruction replaces a normal piece of the examine action, the standard examining rule, with another one of our own devising. (The replacement of the standard examining rule will be explained in more detail in the chapter on rulebooks.)

Printing the description of something is an activity.

This is the fancy examining rule:
    carry out the printing the description activity with the noun.

All we have done here is enclose what is usually just a rule inside an activity. This means that we can now write before and after rules for the activity, and also add special instructions like "Rule for printing the name of something while printing the description of something" -- this may not be likely to arise often, but Inform now has the concept of "printing the description of something" as a separate context of action. Next we add the modification that lets us append to the description without a new line:

Rule for printing the description of something (called item):
    say "[description of item] [run paragraph on]".

"run paragraph on" here will mean that we do not get a paragraph break following the description, even if it ends with a period. We also insert a space, so that our follow-on comments will be properly punctuated.

After printing the description of something charred:
    say "It is charred." instead.

The instead at the end of this line stops Inform for going on with any other "after printing the description of..." rules.

And now, because we want to make sure that we always do get a paragraph break after our description, we add this rule last after all the other rules. "Last" and "first" rules are covered in more detail in the chapter on rulebooks.

Last after printing the description of something:
    say paragraph break.

Section 2 - The Scenario

The Desert Isle is a room. "A pale expanse of sand, here and there developing into hillocks of grass, and a small clump of palms. The water is shallow here, and there are other islands within swimming distance -- or even wading distance, perhaps -- but none of them is any larger than your island, so it doesn't seem worth the trouble of visiting.

A few hundred feet out, the water turns darker blue, the sea floor drops away, and there is nothing to be seen all the way down to the horizon, except a couple of fluffy clouds, and an occasional bird.

The remains of your fire smolder in the stone-lined pit."

A thing can be charred or whole. A thing is usually whole. Instead of burning something: say "You hold [the noun] to the fire until it flares and chars."; change the noun to charred.

The player carries a stick. The description of the stick is "A strip of palm from the woodiest part of the leaf, about a foot and a half long."

The player carries a glass bottle and a piece of paper. The description of the paper is "A single blank sheet." In the glass bottle is a grain of sand. The glass bottle is openable and open. Instead of burning the glass bottle: say "You hold the bottle to the flame, but it grows uncomfortably warm."

Instead of burning the grain of sand: say "You drop the grain into the fire pit, where it becomes indistinguishable from all the others."; remove the grain of sand from play. Instead of dropping the grain of sand: remove the grain of sand from play; say "You return the grain of sand to its brethren."

The player's description is handled in an unusual way, and this will produce a space paragraph break there where it should not. Instead, therefore, we will add an instead for examining the player (probably a good idea anyway):

Instead of examining the player:
    say "You are sunburned and there is sand in cracks you didn't know existed."

Test me with "i / x stick / x bottle / x sand / x paper / x me / burn stick / x stick / burn paper / x paper".

The "printing a description" activity may be useful for other games, and can be imported just by lifting section 1.


PreviousContentsNext