Chapter 18: Activities
§18.1. What are activities?; §18.2. How activities work; §18.3. Rules applied to activities; §18.4. While clauses; §18.5. New activities; §18.6. Activity variables; §18.7. Beginning and ending activities manually; §18.8. Introduction to the list of built-in activities; §18.9. Deciding the concealed possessions of something; §18.10. Printing the name of something; §18.11. Printing the plural name of something; §18.12. Printing a number of something; §18.13. Listing contents of something; §18.14. Grouping together something; §18.15. Issuing the response text of something; §18.16. Printing room description details of something; §18.17. Printing inventory details of something; §18.18. Printing a refusal to act in the dark; §18.19. Printing the announcement of darkness; §18.20. Printing the announcement of light; §18.21. Printing the name of a dark room; §18.22. Printing the description of a dark room; §18.23. Constructing the status line; §18.24. Writing a paragraph about; §18.25. Listing nondescript items of something; §18.26. Printing the locale description of something; §18.27. Choosing notable locale objects for something; §18.28. Printing a locale paragraph about; §18.29. Deciding the scope of something; §18.30. Clarifying the parser's choice of something; §18.31. Asking which do you mean; §18.32. Supplying a missing noun/second noun; §18.33. Reading a command; §18.34. Implicitly taking something; §18.35. Printing a parser error; §18.36. Deciding whether all includes; §18.37. Printing the banner text; §18.38. Printing the player's obituary; §18.39. Amusing a victorious player; §18.40. Starting the virtual machine
![]() | Contents of Writing with Inform |
![]() | Chapter 17: Understanding |
![]() | Chapter 19: Rulebooks |
![]() | Indexes of the examples |
§18.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.
![]() | Start of Chapter 18: Activities |
![]() | Back to Chapter 17: Understanding: §17.21. Precedence |
![]() | Onward to §18.2. How activities work |
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:
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:
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:
and then write a rule that applies to multiple rooms at once, like:
Inform's usual rule-ranking also means that more-specific rules will override less-specific ones, so we could add
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.
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:
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:
Next, we need the standard examining rule to look at our printing-the-description activity:
Now we do the same thing to room descriptions.
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.
|
|
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:
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:
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:
and then write a rule that applies to multiple rooms at once, like:
Inform's usual rule-ranking also means that more-specific rules will override less-specific ones, so we could add
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.
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:
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:
Next, we need the standard examining rule to look at our printing-the-description activity:
Now we do the same thing to room descriptions.
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.
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:
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:
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:
and then write a rule that applies to multiple rooms at once, like:
Inform's usual rule-ranking also means that more-specific rules will override less-specific ones, so we could add
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.
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:
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:
Next, we need the standard examining rule to look at our printing-the-description activity:
Now we do the same thing to room descriptions.
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.
|