19.7. Indexed text in variables, properties and tables

| Chapter 19: Advanced Text |

| 19.7. Indexed text in variables, properties and tables

So far we have been able to ignore the difference between "text" and "indexed text" because Inform has always been able to convert the former to the latter when needed. But the reverse conversion cannot be made. Ordinary text is stored in a specially compacted, read-only form: it's really part of the program, not part of the data.

The upshot of this is that if we need a variable to contain text which can be internally altered during play, then we must declare this. Instead of writing

> The player's forename is a text that varies.

we must write:

> The player's forename is an indexed text that varies.

Similarly for a property:

> A person has an indexed text called nickname.

For a named "let" value, we have a dilemma. These are normally created by writing something like:

> let the target be 17;

and Inform looks at the value - here 17, a number - to deduce that the new value, called "target", must be a number. So if we write:

> let the target be "excellent";

the result is that "target" is just a text, not an indexed text. We get around this by writing instead:

> let the target be an indexed text;

which creates the value, initially having the empty text as contents, and then

> let the target be "excellent";

to subsequently set its initial state.

The same issue arises for table columns, because we are allowed to simply write out values in table columns, and let Inform work out what kind they are. If there are blank entries, we can always write in the kind of value by hand, but suppose the entries are initially all filled in? The answer is that we can imitate this:

> Table of Neptune's Moons

> moon | surface (indexed text)
> "Nereid" | "utterly unknown"
> "Triton" | "cryovolcanic ridges"
> "Proteus" | "highly irregular and sooty"

Here the two columns are called "moon" and "surface", so we can talk about the "moon entry" and the "surface entry" once a row has been chosen: but the moon entry is text, and the surface entry is indexed text.

Lastly, suppose we want to define new phrases which deal with text. Here we have two things to remember. First, we need to say that the value decided is indexed text, not text; secondly, that text converts to indexed text by magic, but not vice versa. So:

> To decide what indexed text is (T - text) doubled:
> decide on "[T][T]".

works fine so long as we only want to pass text to it, but would not let us double indexed text. This, on the other hand, handles both:

> To decide what indexed text is (T - indexed text) doubled:
> decide on "[T][T]".

So for instance:

> say "Neptune" doubled.

prints "NeptuneNeptune" because Inform automatically converts "Neptune" to indexed text when "doubled" is used on it.

405
| Example Identity Theft Allowing the player to enter a name to be used for the player character during the game. |
RB

406
| Example Mirror, Mirror The sorcerer's mirror can, when held up high, form an impression of its surroundings which it then preserves. |
RB

"Mirror, Mirror" The Sorcerer's Workshop is a room. "The sorcerer's den is a dusty, whispering place. A grandfather clock with skeletal hands reads [the time of day in words]. The floorboards are stained where that porridge just wouldn't come out." The Apprentice's Pantry is east of the Workshop. "This is where the aproned apprentice traditionally makes the camomile tea, cleans out the jackdaw cages and furtively examines purloined artefacts." When play begins: erase the mirror. The player carries a magic mirror. The magic mirror has indexed text called mirror vision. To erase the mirror: now mirror vision of the mirror is "The mirror is polished clean, and has no impression upon it." To say current room description: try looking. To expose the mirror: say "The mirror shines momentarily with a dazzling light.[paragraph break]"; now mirror vision of the mirror is "The hazy image in the mirror preserves a past sight:[line break][current room description]All is distorted and yet living, as though the past and present are coterminous in the mirror." Understand "hold up [something preferably held]" or "hold [something preferably held] up" as holding aloft. Holding aloft is an action applying to one carried thing. Report holding aloft: say "You hold [the noun] aloft." Instead of rubbing the mirror: erase the mirror; try examining the mirror. Instead of holding aloft the mirror: expose the mirror. The description of the mirror is "[mirror vision of the mirror]". Test me with "look / examine mirror / hold up mirror / z / look / x mirror / rub mirror / east / hold mirror up / west / x mirror".

407
| Example The Cow Exonerated Creating a class of matches that burn for a time and then go out, with elegant reporting when several matches go out at once. |
RB

Previous | Contents | Next