17.1. What are activities?

| Chapter 17: Activities |

| 17.1. What are activities?

It is poor form to define with negatives, but the first thing to say about activities is that they are not actions. This needs saying because Inform often seems to treat them as if they are, by allowing us to write rules like so:

> Before printing the name of a woman, say "Ms ".

With this rule in place, someone called "Daphne" will always be described as "Ms Daphne", and so on. The language looks as if we were imposing a rule on an action called "printing the name of", but there is no such action: instead, it is an "activity". To spell out the difference:

> An action is a simulated task for the fictional protagonist.

> An activity is a real task for the computer program doing the simulation.

Activities allow us to influence or change some of the standard habits of Inform, using rules as flexible and powerful as those applicable to actions, though activities are in several ways simpler and easier.

321
| Example Ant-Sensitive Sunglasses What are activities good for? Controlling output when we want the same action to be able to produce very flexible text depending on the state of the world -- in this case, making highly variable room description and object description text. |
RB

Suppose we want to create an object -- or maybe even a series of objects -- that warp the player's perception of every room description and object around him. We've already seen some ways to create variations in text. For instance, we could make a room description with if substitutions in it, like so: The Kitchen is a room. "[if the player is wearing the sunglasses]Are ants coming out of the sink? No, probably no.[otherwise]A small kitchen tucked into a corner of the vacation house. There is storage space for five or six cups, a sink, a two-ring stove; nothing else to speak of.[end if]" That works fine if we have one or two variations we want to add; it's not so good if we're going to have several items that work like the sunglasses, or if we want the sunglasses to override the description of every room in the house. A slightly more flexible method is to use a substitution that calls out to a say phrase, like this: The Kitchen is a room. "[kitchen-description]" To say kitchen-description: if the player is wearing the sunglasses: say "Are ants coming out of the sink? No, probably no."; otherwise: say "A small kitchen tucked into a corner of the vacation house. There is storage space for five or six cups, a sink, a two-ring stove; nothing else to speak of." But again this doesn't handle the case of overriding multiple rooms at once very well. When we reach a point where we need a given piece of text to be very flexible depending on the world model, it's time to use an activity. Activities offer several advantages. One, we can create an activity like this: Printing the room-description of something is an activity. and then write a rule that applies to multiple rooms at once, like: Rule for printing the room-description of a room when the player wears the sunglasses: say "The walls look like they're covered with ants. Just a coincidence, I'm sure." Inform's usual rule-ranking also means that more-specific rules will override less-specific ones, so we could add Rule for printing the room-description of the Kitchen when the player wears the sunglasses: say "Are ants coming out of the sink? No, probably not." and have that rule override the behavior of the activity just in the kitchen. Meanwhile, our base room descriptions remain straightforward and uncluttered by if-statements. Several other examples will show how to hook activities into existing actions: Crusoe goes into detail about how how to make the descriptions of things more variable, and Aftershock demonstrates activities for describing the behavior of switchable devices. Here, we preview all of those methods, just to get a sense of how they work and why they might be useful in controlling a game. Subsequent chapters go into more detail about the syntax of creating activities and the list of activities that are already defined by Inform. "Ant-Sensitive Sunglasses" Part 1 - Procedure To add a new activity to an existing Inform rule, we need to do three things: 1) Define our new activity. 2) Give a basic rule that says what is supposed to happen when that activity occurs, as in "Rule for..." 3) Replace the existing rule in Inform's rulebooks with a new one that calls on our activity. Here we do this with examining: Section 1 - Item Description Printing the description of something is an activity. Now, by default, we want to print the description property; we just want the option to write some extra rules overriding that property. So we tell Inform that our most basic rule for printing the description of something is just to give that description text: Rule for printing the description of something (called item): if the description of the item is not "": say "[description of item][paragraph break]"; otherwise: say "You see nothing special about [the item].". Next, we need the standard examining rule to look at our printing-the-description activity: The activity-based examining rule is listed instead of the standard examining rule in the carry out examining rules. This is the activity-based examining rule: carry out the printing the description activity with the noun; rule succeeds. Now we do the same thing to room descriptions. Section 2 - Room Description Printing the room-description of something is an activity. Rule for printing the room-description of a room (called item): if the description of the item is not "": say "[description of item][paragraph break]"; otherwise: do nothing instead. The activity-based room description body text rule is listed instead of the room description body text rule in the carry out looking rules. Our replacement rule this time around is a little bit trickier just because the rule that we're replacing is a complicated one: describing a room already checks to see whether there's light to see by, whether the player has turned off room descriptions when he enters a room for the second time, and whether the player character is (say) inside a closed box he can't see out of. But all of those details are re-copied from the standard rules, and the important thing is that, at the end, we again carry out our activity. This is the activity-based room description body text rule: if the visibility level count is 0: if set to abbreviated room descriptions, continue the action; if set to sometimes abbreviated room descriptions and abbreviated form allowed is true and darkness witnessed is true, continue the action; begin the printing the description of a dark room activity; if handling the printing the description of a dark room activity, issue miscellaneous library message number 17; end the printing the description of a dark room activity; otherwise if the visibility ceiling is the location: if set to abbreviated room descriptions, continue the action; if set to sometimes abbreviated room descriptions and abbreviated form allowed is true and the location is visited, continue the action; carry out the printing the room-description activity with the location. Section 3 - Device Description Showing action of something is an activity. Rule for showing action of something (called item): if the item is switched on, say "[The item] is switched on."; otherwise say "[The item] is switched off." The activity-based described devices rule is listed instead of the examine devices rule in the carry out examining rules. This is the activity-based described devices rule: if the noun is a device: carry out the showing action activity with the noun; now examine text printed is true. Report switching on something: say "You flip a switch. "; carry out the showing action activity with the noun instead. Part 2 - Scenario Include Plurality by Emily Short. The Kitchen is a room. "A small kitchen tucked into a corner of the vacation house. There is storage space for five or six cups, a sink, a two-ring stove; nothing else to speak of." The microwave is a device in the Kitchen. South of the Kitchen is the Living Area. The description of the Living area is "A whitewashed living/dining/reclining area in what used to be a shepherd's stone hut, but now costs vacationers 600 euros a week. It offers no mod cons, only a straight view of the Mediterranean and a wobbly writing table." Rule for printing the room-description of a room when the player wears the sunglasses: say "The walls look like they're covered with ants. Just a coincidence, I'm sure[antsy]." Rule for printing the room-description of the Kitchen when the player wears the sunglasses: say "Are ants coming out of the sink? No, probably not[antsy]." Rule for printing the description of something (called the item) when the player wears the sunglasses: say "[The item] [is-are] [one of]ant-colored[or]ant-legged[or]covered in ants[at random][antsy]." Rule for showing action of the microwave: say "The microwave hums meaningfully to itself." Rule for showing action of the microwave when the player wears the sunglasses: say "The microwave hums as though inhabited by a billion ants[antsy]." The player carries sunglasses of freakiness and an apple. The apple is edible. The sunglasses are wearable. ant-paranoia is a number that varies. To say antsy: increase ant-paranoia by 1; Every turn: if the ant-paranoia is greater than 3: say "Augh! AUUUGH! GET THEM OFF--"; end the story saying "You have lost your mind." Test me with "look / turn on microwave / turn off microwave / x apple / x sunglasses / s / wear sunglasses / look / x apple / n / turn on microwave".

Previous | Contents | Next