17.5. New activities

| 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 value (usually an object but not necessarily), and those which do not. Here are some examples of activities being created:

> Assaying is an activity.
> Analysing something is an activity.
> Announcing something is an activity on numbers.

Inform looks for the clue "something" (or "of something") after the activity's name to see if it will work on a value: so analysing and announcing will do, but assaying won't. If we don't specify a kind, Inform assumes the value will be an object, as if we had written:

> Analysing something is an activity on objects.

As always in Inform, the names of activities are themselves values.

> "assaying activity" has kind activity on nothing
> "analysing activity" has kind activity on objects
> "announcing activity" has kind activity on numbers

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. Just as it does for rulebooks, Inform defines the adjectives "empty" and "non-empty" for activities to test this state:

> if the analysing activity is empty, ...

will be true only when all three of its rulebooks are empty.

A newly created activity never happens unless we take steps to make it do so. We can make an activity happen at any time by writing phrases like so:

carry out the (activity) activity

This phrase carries out the given activity, which must be one not applying to any value. Example: carry out the assaying activity;

carry out the (activity on values) activity with (value)

This phrase carries out the given activity, which must apply to a kind of value matching the one supplied. Example: carry out the analysing activity with the pitchblende; carry out the announcing activity with the score;

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

> Rule for announcing a number (called N): say "Ladies and gentlemen, [N]."

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

The "for" rulebook is one where rules stop the activity, by default, when they take effect - in the same way that the "instead" rules stop actions by default. If this causes problems, we can use:

continue the activity

This phrase should be used only in rules in activity rulebooks. It causes the current rule to end, but without result, so that the activity continues rather than stopping as a result of the rule. This is useful for rulebooks (like the "for" rulebook of an activity) where the default is that a rule does stop the activity.

Activities are more useful than they first appear. Every new one 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.

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

Suppose we have a complete Encyclopedia in our game. The player is allowed to pick up the whole set (there must not be too many volumes), but also to do things with individual volumes, and indeed to scatter these volumes all over the place. Putting a volume back in the same place as the rest of the Encyclopedia should, however, restore it to the collective. We will start out by defining general rules for collectives like this: "AARP-Gnosis" Fitting relates various things to one thing (called the home). The verb to fit (it fits, they fit, it is fitted) implies the fitting relation. Definition: a thing is missing if it is not part of the home of it. A collective is a kind of thing. Before doing something to something which is part of a collective: let space be the holder of the home of the noun; move the noun to the space. Instead of examining a collective: say "[The noun] consists of [the list of things which are part of the noun]." Now the real work begins. One reason to make this an activity is that we might easily want to override it for specific objects; for instance, the generic collecting activity here would not deal properly with collectives of clothing where some items might be worn and others not. In that case, we would want to write another, more specific "collecting" activity to handle the complexities of fashion. Collecting something is an activity. Every turn: repeat with item running through collectives: carry out the collecting activity with the item. To remove (item - a thing) when empty: let space be the holder of the item; if the number of things which are part of the item is 0, remove the item from play; if the number of things which are part of the item is 1: let the last thing be a random thing which is part of the item; move the last thing to the space; remove the item from play. Before collecting a thing (called the item): remove item when empty; let space be the holder of the item; if space is not a thing and space is not a room: if something (called the other space) contains at least two things which fit the item, move item to the other space; if a room (called the other space) contains at least two things which fit the item, move item to the other space; if someone (called the owner) carries at least two things which fit the item, move item to the owner. Rule for collecting a thing (called the item): let space be the holder of the item; if space is a thing or space is a room: repeat with component running through things held by the space: if the component fits the item, now the component is part of the item; remove item when empty. And now for a cheerful scenario: The Boise Memorial Library is a room. "A concrete box of a room, roughly eight feet by fourteen, which contains all the fallout shelter has to offer by way of entertainment. Someone with a grim sense of humor has tacked a READ! literacy poster to the door, as though there were anything else to do while you await the calming of the Geiger counters." The shelf is a supporter in the Library. "A battered utility shelf stands against the south wall." The New Idahoan Encyclopedia Set is a collective. Volume A-Aalto fits the Encyclopedia. It is part of the Set. Volume AAM-Aardvark fits the Encyclopedia. It is part of the Set. Volume Aarhus-Aaron fits the Encyclopedia. It is part of the Set. Volume AARP-Gnosis fits the Encyclopedia. It is part of the Set. Volume Gnu-Zygote fits the Encyclopedia. It is part of the Set. The Set is on the shelf. Let's have the Encyclopedia describe itself differently depending on whether it's all in one place: After printing the name of the Set when something missing fits the Set: say " (missing [a list of missing things which fit the Set])" Before printing the name of the Set when the number of missing things which fit the set is 0: say "complete ". Test me with "get aarhus-aaron / look / inventory / get aam-aardvark / look / get gnu-zygote / look / get aarp-gnosis / look / inventory / drop set / look / get set / get a-aalto / inventory".

323
| Example Crusoe Adding a "printing the description of something" activity. |
RB

324
| 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

Previous | Contents | Next