8.1. Change of values that vary

| Chapter 8: Change |

| 8.1. Change of values that vary

So far, what we have done in response to the player's commands amounts to little more than a few ripostes. The simulated world does change during play, as the player moves from room to room or picks up things, but all of this is happening automatically, not at our direct instruction. How then can we make the world change?

Recall that the world consists of rooms, in which are things, and that all of these have properties appropriate to their kinds. Some properties are either/or ("open" or "closed" but not both and not neither), while others have values (the "matching key" of a lockable door, for instance). Finally, we may also have created some free-standing values or "variables".

We take the last example first, as it is the simplest. Suppose we have:

> "Winds of Change"

> The prevailing wind is a direction that varies. The prevailing wind is northwest.

> The Blasted Heath is a room. "Merely an arena for the play of witches and kings, my dear, where the [prevailing wind] wind blows."

> Instead of waiting when the prevailing wind is northwest:
> say "A fresh gust of wind bowls you over.";
> now the prevailing wind is east.

The new phrase here is "now". This automatically checks that the new value is one which makes sense in the given context, so for instance it would not allow either of these:

> now the prevailing wind is 25;
> now the prevailing wind is the Heath;

the former being a number, and the latter a room, so that neither is a direction. Similarly, "now" will not allow constant values to be changed. So

> Colour is a kind of value. The colours are blue, red and mauve.

> After pulling the psychedelic lever:
> now blue is mauve.

...will result in a problem message; it's like writing "now 1 is 2". The difference between "the prevailing wind" and "blue" is that the wind was declared to be a "direction that varies", whereas blue wasn't.

| At present Inform allows: change (a stored value) to (value) or: change (object) to (property) or: change (object) to (enumerated value)
This phrase changes the given stored value (a variable, table entry, property, or list entry) to the value supplied. Example: change the prevailing wind to south; This goes back to the very early days of Inform, before "now" was as flexible as it is today, and it is now deprecated. Future builds of Inform will withdraw it completely. "Now" can do anything "change" can do: now the prevailing wind is south; "change ... to ..." has a complicated definition (hence the three alternative forms) because it also allowed, for instance: change the location to visited; which didn't change the value of "location" at all, but instead gave that value the property of being "visited". This leads to awkward ambiguities, which are another reason for "change" being withdrawn. Again, "now" does this better: now the location is visited;

Previous | Contents | Next