Inform 7 Home Page / Documentation
§5.13. Making new substitutions
If we have some textual effect which needs to occur in several different messages, we might want to create a new text substitution for it. For instance:
The Missile Base is a room. "[security notice]Seems to be a futuristic missile base." M's Office is east of the Missile Base. "[security notice]Admiral Sir M.- M.- glares up from his desk."
To say security notice:
say "This area is a Prohibited Place within the meaning of the Official Secrets Act 1939. "
This is only the tip of the iceberg in how to define ways to do things using "To...", as we shall see. The definition makes "say the security notice" a new phrase known to Inform. A text substitution is exactly a phrase whose name begins with "say" (well - except for the "say" phrase itself), so the effect is that "[security notice]" is a new text substitution. Several of the examples in this chapter make use of this trick.
Inform often ignores the casing of the text it reads, but sometimes uses it as a clue to meaning. We have already seen that "[an item]" and "[An item]" produce different results, for instance. Similarly, it's possible to define two text substitutions which are the same except for the initial casing. We might write:
To say Security Notice:
say "THIS AREA IS A PROHIBITED PLACE WITHIN THE MEANING OF THE OFFICIAL SECRETS ACT 1939. "
And now Inform will act on "[Security Notice]" differently from "[security notice]".
See The phrasebook for other forms of phrase besides To say...
|Start of Chapter 5: Text|
|Back to §5.12. Displaying quotations|
|Onward to Chapter 6: Descriptions: §6.1. What are descriptions?|
Fifty Ways to Leave Your Larva
We can use these substitutions to put together fairly complicated variations within a single piece of text:
In this context, [denial] is understood to refer to the denial property of the noun -- but we could spell it out with "denial of the noun" if we wanted to.
And then it would be trivial to insert further rules using these responses:
Fifty Times Fifty Ways
There is only so much we can cram into a text property, so being able to swap in properties is useful but limited. Fortunately, we can also, if we want, create new phrases for how to say things in brackets:
A person can be fierce or mellow. Wasp is fierce. Drone is mellow. A person can be calm or angry. A person is usually calm. A person has some text called insult. The insult of a person is usually "Grasshopper". The insult of Wasp is "Larva".
Now to provide some meaning to these bracketed forms. We'll start with the easy one:
This is a "to say" phrase; we will learn more about phrases in a later chapter, but for now it may be enough to observe that whatever we write after "to say..." becomes a valid substitution in bracketed speech. In this particular case there is no advantage to using the boast token rather than spelling the text out in the quotation, but we might in theory add further instructions to randomize the output, for instance.
To say phrases can be more complex, as well, since we can have them incorporate extra information:
Here where we have (speaker - a person), we are leaving a slot which we can later fill in, madlibs-like, with any person we like. That is why we can write "insult for the noun": we are summoning the To say phrase and telling it to fill in the identity of the unknown speaker with the noun.
This differs from "insult of the noun" in the previous example; in that case, each person had his own insult property, and were merely printing that property out. Here we are actually telling Inform to calculate anew what the insult should be, and giving it some instructions about how to do that.
Our instructions can also get arbitrarily complex:
So the effects we can get with text substitutions are quite flexible. We could even, if we wanted, fill in the substitutions by random choice, or by selecting items from a long list or table, should we have so bellicose a set of characters that they cannot make do with one or two insulting remarks apiece.