11.5. Conditions and questions

| Chapter 11: Phrases |

| 11.5. Conditions and questions

A variety of "conditions" have already appeared in this documentation. A condition is a phrase which describes a situation which might be true, or might be false, and examples might include:

> Mr Kite is in Bishopsgate
> the score is greater than 10
> Sherlock Holmes suspects a woman

These are all examples of sentences, formed by putting nouns either side of a verb, and clearly a wide range of conditions can be written this way. But there are also a few special conditions built into Inform which have a fixed wording, and test questions difficult to address with ordinary sentences. For instance:

if in darkness:

This condition is true if the player currently has no light to see by. Note that the test is more complicated than simply testing if the player is in a dark room, ... since the player might have a torch, or be inside a cage which is itself in a dark room, and so on.

Another example of a condition not easily written as a sentence is:

if player consents:

This condition is unusual in doing something and not simply making a silent check: it waits for the player to type YES (or Y) or NO (or N) at the keyboard, and then is true if the answer was yes. Example: say "Are you quite sure you want to kiss the Queen? "; if the player consents: ...

Whether it's put to the player like this or not, testing a condition is really asking a question, and there is always a yes/no answer. In Inform this answer is not usually a value (unlike in some other computer programming languages), but it can be made into one.

Firstly, we need a special kind of value to hold answers like this. It's called "truth state", and it has just two possible values, written as "true" and "false". We then need:

whether or not (a condition) ... truth state

This phrase converts a condition into its result as a value, which is always either "true" or "false". Example: whether or not 20 is an odd number produces the truth state "false". This is mostly useful for storing up results to look at later: let victory be whether or not all the treasures are in the cabinet; and then subsequently: if victory is true, ...

As another example, in most stories this:

> When play begins:
> showme whether or not in darkness.

...will produce a line:

> "whether or not in darkness" = truth state: false

In short, "truth state" is a kind of value like any other. That means it can be the kind of a variable:

> Salvation earned is a truth state that varies.

and it can similarly be used in table columns, lists, or anywhere else where values are allowed.

171
| Example Proposal Asking the player a yes/no question which he must answer, and another which he may answer or not as he chooses. |
RB

Previous | Contents | Next