§20.7. Making new text with text substitutions
Substitutions are most often used just for printing, like so:
say "The clock reads [time of day].";
But they can also produce text which can be stored up or used in other ways. For example, defining
To decide what text is (T - text) doubled:
decide on "[T][T]".
makes
let the Gerard Kenny reference be "NewYork" doubled;
set this temporary variable to "NewYorkNewYork".
There is, however, a subtlety here. A text with a substitution in it, like:
"The clock reads [time of day]."
is always waiting to be substituted, that is, to become something like:
"The clock reads 11:12 AM."
If all we do with text is to print it, there's nothing to worry about. But if we're storing it up, especially for multiple turns, there are ambiguities. For example, suppose we're changing the look of the black status line bar at the top of the text window:
now the left hand status line is "[time of day]";
Just copying "[time of day]" to the "left hand status line" variable doesn't make it substitute - which is just as well, or the top of the screen would perpetually show "9:00 AM".
On the other hand, looking back at the phrase example:
To decide what text is (T - text) doubled:
decide on "[T][T]".
"[T][T]" is substituted immediately it's formed. That's also a good thing, because "T" loses its meaning the moment the phrase finishes, which would make "[T][T]" meaningless anywhere else.
What's going on here is this: Inform substitutes text immediately if it contains references to a temporary value such as "T", and otherwise only if it needs to access the contents. This is why "[time of day]" isn't substituted until we need to print it out (or, say, access the third character): "time of day" is a value which always exists, not a temporary one.
Using the adjectives "substituted" and "unsubstituted", it's always possible to test whether a given text is in either state, should this ever be useful. For example,
now the left hand status line is "[time of day]";
if the left hand status line is unsubstituted, say "Yes!";
will say "Yes!": the LHSL is like a bomb waiting to go off. Speaking of which:
The player is holding a temporal bomb.
When play begins:
now the left hand status line is "Clock reads: [time of day]".
After dropping the temporal bomb:
now the left hand status line is the substituted form of the left hand status line;
say "Time itself is now broken. Well done."
This is making use of:
substituted form of (text) ... text
This takes a text and makes substitution occur immediately. For example,
substituted form of "time of death, [time of day]"
produces something like "time of death, 9:15 AM" rather than "time of death, [time of day]". It's entirely legal to apply this to text which never had any substitutions in, so
substituted form of "balloon"
produces "balloon".
Note that there's no analogous phrase for "unsubstituted form of...", because once text has substituted, there's no way to go back.
![]() | Start of Chapter 20: Advanced Text |
![]() | Back to §20.6. Regular expression matching |
![]() | Onward to §20.8. Replacements |
|
|
Here we create a class of matches that can be used to burn other objects. Our objectives are as follow: Burned objects other than matches should be removed from play instantly (just as edible objects are instantly eaten). We could give everything its own burning duration, but that complicates matters and allows for fire to spread from one object to another; for an example of how to do that, see the example "In Fire or in Flood". Matches should be described to show whether they are burning or extinguished, and when the parser chooses one of several identical matches, it should make very clear which match it has selected. The game must sensibly select and, if necessary, automatically light new matches to carry out a >BURN THING command. The matches must burn for a set number of turns before going out, never to be used again. And finally, the part for which the text will be useful: when several matches go out in the same turn, we want the game to print
rather than
This last function appears down in Section 3, if we wish to skip ahead and look at it.
The word "matches" is used by Inform to compare snippets of text (see "Reading a command" in the Activities chapter). This can sometimes cause awkwardness if we also have a kind called "match", so for the occasion we will give our matches a more specialized name, never visible to the player:
|
|
Here we create a class of matches that can be used to burn other objects. Our objectives are as follow: Burned objects other than matches should be removed from play instantly (just as edible objects are instantly eaten). We could give everything its own burning duration, but that complicates matters and allows for fire to spread from one object to another; for an example of how to do that, see the example "In Fire or in Flood". Matches should be described to show whether they are burning or extinguished, and when the parser chooses one of several identical matches, it should make very clear which match it has selected. The game must sensibly select and, if necessary, automatically light new matches to carry out a >BURN THING command. The matches must burn for a set number of turns before going out, never to be used again. And finally, the part for which the text will be useful: when several matches go out in the same turn, we want the game to print
rather than
This last function appears down in Section 3, if we wish to skip ahead and look at it.
The word "matches" is used by Inform to compare snippets of text (see "Reading a command" in the Activities chapter). This can sometimes cause awkwardness if we also have a kind called "match", so for the occasion we will give our matches a more specialized name, never visible to the player:
Here we create a class of matches that can be used to burn other objects. Our objectives are as follow: Burned objects other than matches should be removed from play instantly (just as edible objects are instantly eaten). We could give everything its own burning duration, but that complicates matters and allows for fire to spread from one object to another; for an example of how to do that, see the example "In Fire or in Flood". Matches should be described to show whether they are burning or extinguished, and when the parser chooses one of several identical matches, it should make very clear which match it has selected. The game must sensibly select and, if necessary, automatically light new matches to carry out a >BURN THING command. The matches must burn for a set number of turns before going out, never to be used again. And finally, the part for which the text will be useful: when several matches go out in the same turn, we want the game to print
rather than
This last function appears down in Section 3, if we wish to skip ahead and look at it.
The word "matches" is used by Inform to compare snippets of text (see "Reading a command" in the Activities chapter). This can sometimes cause awkwardness if we also have a kind called "match", so for the occasion we will give our matches a more specialized name, never visible to the player:
|