Phrases are instructions to Inform to do something, or to decide whether something is true or false, or to produce a value, or to say something. Inform has around 350 phrases built-in, and the chapters so far have already defined about 100 of those. In this chapter we'll see some key phrases for organising instructions of what to do, and also see how to define entirely new phrases.
Just to run through the four sorts of phrase with examples:
(a) Phrases to do something. These are the ones used in the body of a rule. For example,
When Train Stop begins:
move the Flying Scotsman to the Station;
say "The Flying Scotsman pulls up at the platform."
Rules like this begin with a "preamble", the beginning part which tells Inform when or how they apply, and then follow on with a list of instructions - here, just two of them. "move … to …" and "say …" are both phrases. Inform provides about 130 of these built-in. It's actually not quite true that they all do something, because one of them is:
do nothing
This phrase does nothing at all. It is very occasionally useful to make a rule which does nothing:
This is the largely ineffective rule:
do nothing.
(b) Phrases to decide whether a condition is true. These are the ones which can be used in an "if":
if action requires light: ...
Not all conditions come from phrases. For example, "if the front door is closed" and "if Peter is wearing the sandals" have meanings which come from the verbs "to be" and "to wear". Inform provides about 60 built-in conditions, which give a friendly wording for questions which would be lengthy or difficult to write in any other way.
(c) Phrases to decide a value. For example:
square root of 16
produces a number, 4 of course, and can be used whenever a number is expected. Inform provides about 100 built-in phrases like this.
(d) Text substitutions. These are actually just phrases whose definition begins with "To say …". Example:
"It's now [time of day in words]."
Inform provides about 60 built-in text substitutions.
The Phrasebook is Inform's collection of recognised phrases, and it can always be browsed using the Index panel of the same name. Even the smallest project has a good-sized phrasebook, since it contains all of the built-in phrases. But most projects also define new phrases of their own.
Here is a simple definition of a new phrase:
To spring the trap:
say "'Sproing!' go the hinges and, with a flash of silver, the enormous blades whisk together!";
end the story.
Inform allows us to use whatever conventions of layout we prefer, but it's customary to use indentation like this, dividing off the preamble from the phrases which follow. As can be seen, definitions of new phrases look very like rules.
What makes this definition a simple one is that the wording is fixed. The only way to use this would be from another phrase or rule, like so:
Instead of entering the cage:
spring the trap.
In the next section we'll see how to give more complicated definitions which, like "move … to …", allow for the wording to change with the circumstances.
In this section, let's make the following new phrase:
To admire (item - an object):
say "You take a long look at [item].".
This does very little, of course, but it does allow the wording to be different each time the phrase is used:
admire the diamonds;
admire Mr Cogito;
admire the honey sandwich;
and our single definition covers all of these possibilities. The bracketed part of the definition, "(item - an object)", tells Inform to expect an object in that position, and Inform enforces this carefully. So this definition might tell Inform what "admire the barricade" means, but not what
admire "blue cheese";
admire 63;
mean. Unless some other definition sorts the matter out, Inform will reply to uses like this with a Problem message:
Problem. You wrote 'admire 63' , but '63' has the wrong kind of value: a number rather than an object.
The object does not need to be named literally, but can be anything which works out to be an object: for instance,
After dropping something in the Auction House:
admire the noun.
which Inform allows because "noun", here, is a name for the object which is being acted on.
Inform decides which definition to apply in a process called "pattern matching".
The bracketed part of the example definition has the form "(name - kind)". The definition only applies if the text supplied agrees with the "kind" part - for instance, the diamonds agreed with "object", but 63 did not. If the definition does apply, then the Inform works through the rest of the phrase using "name" to mean whatever value matched. For example:
To slam shut (box - an open container):
say "With great panache, you slam shut [the box].";
now the box is closed.
When this phrase is followed, "box" means whatever open container the pattern-matcher found when it was called for. For example, if Inform reads
slam shut the Dutch armoire;
then it acts on this by following the definition of "slam shut …", using the Dutch armoire object as the value of "box", so it prints:
With great panache, you slam shut the Dutch armoire.
and renders it closed.
In fact any description can be given in the definition, and that includes a single, specific value. For instance, we could define:
To grant (bonus - a number) points:
increase the score by the bonus.
To grant (bonus - 7) points:
say "You shiver uncontrollably."
which would withhold this unlucky bounty. That would mean that:
grant 7 points;
grant seven points;
would each produce uncontrollable shivers, because Inform uses the definition applying to the number 7; but
grant six points;
would increase the score by 6. In general Inform always follows the principle that more specific definitions take priority over more general ones. So although the definitions:
To grant (bonus - a number) points: ...
To grant (bonus - 7) points: ...
both apply to the case of "grant 7 points", Inform uses the second, because it's the more specific of the two possibilities.
Sometimes it will not be possible to tell if the value supplied meets the requirements until the story is actually playing. If, at run-time, no definition fits some phrase which has to be carried out, a run-time problem message is produced.
Finally, and more straightforwardly, we can specify variations in wording using slashes between alternative words in a "To …" definition. For instance:
To grant (bonus - a number) point/points: ...
allows the final word to be either "point" or "points". Slashes like this can only be used with literal words, not bracketed values, and give alternative forms only of a single word at a time; the alternative "--" means "no word at all", and thus makes it optional:
To grant (bonus - a number) point/points/--: ...
makes "grant 3" do the same as "grant 3 points".
If we need more variation than that, we should make more than one definition.
We've already seen the SHOWME command, which can be typed into the Story panel to look at the state of something, usually a thing or room. SHOWME is a testing command which has no effect once the work is released; eventual players can't use it.
Inform also has a phrase called "showme", which works in much the same way:
showme (value)
This phrase is intended for testing purposes only. If used in a story file running inside the Inform application, it prints a line of text showing the given value and its kind; in a Released story file, it does nothing at all. Example:
When play begins: showme 11.
produces
number: 11
More usefully:
Every turn: showme the score.
Now, every turn, we get a line in the story's transcript like so:
"score" = number: 0
Inform uses the quotation marks and equals sign to show that it had to do some work to find the answer. "score" wasn't a constant value - it was a variable, and Inform had to look up the current value.
"showme" is a convenient way to see what's going on inside a phrase which isn't behaving as expected, or to find out the kind of a value. Here are some trickier examples. Suppose our design includes:
The matching key of the blue door is the brass Yale key.
If we then try this:
When play begins:
showme matching key of the blue door.
we get, when the story starts up,
"matching key of the blue door" = object: brass Yale key
Why is this an "object", when we know that the key is actually a "thing"? After all, if we "showme key" instead, we get:
thing: brass Yale key
The answer is a little technical: it's because Inform guarantees that the matching key is always an object, but not that it's always a thing - it just happens to be a thing at the moment. There's not really a contradiction, because a "thing" is a kind of "object", so in fact the key is both. If we try "showme matching key", we get something like this:
objects valued property: property 23
which is even more technical - people never need to print the names of abstract property names during play, so Inform doesn't provide any good way of doing it. It is reduced to printing out an internal ID number ("property 23") instead of the name ("matching key"). This can't be helped: "showme" is a way to lift the lid and see what's going on inside Inform's machinery, and some of the corners are dark.
All the same, "showme" can be very useful in tinkering with rules to make them work properly. It prints nothing at all in a Release version of a project, so it's impossible for these private notes to be shown accidentally to our eventual readers.
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.
Inform's most powerful phrases are those which control the others, making them repeat, or be skipped.
if (a condition) , (a phrase)
or…
if (a condition):
This phrase causes the single phrase, or block of phrases, following it to be obeyed only if the condition is true. (If the condition must contain a comma for some reason, the block form should be used.) Example:
if the red door is open, say "You could try going east?"
The sense of an "if" can be reversed by using the word "unless" instead:
unless (a condition) , (a phrase)
or…
unless (a condition):
This phrase causes the single phrase, or block of phrases, following it to be obeyed only if the condition is false. (If the condition must contain a comma for some reason, the block form should be used.) Example:
unless the red door is closed, say "You could try going east?"
"Unless" is clearly unnecessary, but it can be a good way to make the source text easier for humans to read.
As we have seen, there are many different forms of condition in Inform. They usually take a form quite like an assertion sentence, except that they're questions and not statements of fact. For example:
if the score is 10, ...
if all of the people are in the Atrium, ...
Questions like this are checked by Inform to see if they make sense. The following doesn't, for instance:
if 10 is a door, say "Huzzah!";
This produces the baffled reply:
Problem. In the line 'if 10 is a door, say "Huzzah!"' , I can't determine whether or not '10 is a door', because it seems to ask if a number is some sort of door.
In practice it is not enough to apply "if" to a single phrase alone: we want to give a whole list of phrases to be followed repeatedly, or to be followed only if a condition holds.
We do this by grouping them together, and there are two ways to do this. One is as follows:
To comment upon (whatever - a thing):
if whatever is transparent, say "I see right through this!";
if whatever is an open door:
say "Oh look, an open door!";
if whatever is openable, say "But you could always shut it."
Here we group two phrases together under the same "if". Note that the comma has been replaced by a colon, and that the indentation in the list of phrases shows how they are grouped together. In the example above, the source moves two tabs in from the margin; the maximum allowed is 25.
Indentation is the convention used in this manual and in the examples, but not everybody likes this Pythonesque syntax. So Inform also recognises a more explicit form, in which the beginning and ending are marked with the words "begin" and "end":
To comment upon (whatever - a thing):
if whatever is transparent, say "I see right through this!";
if whatever is an open door
begin;
say "Oh look, an open door!";
if whatever is openable, say "But you could always shut it.";
end if.
(Pythonesque because it's a style popularised by the programming language Python, named in turn after "Monty Python's Flying Circus".)
A SEARCH [room] action that will open every container the player can see, stopping only when there don't remain any that are closed, unlocked, and openable.
We often need code which does one thing in one circumstance, and another the rest of the time. We could do this like so:
if N is 2:
...
if N is not 2:
...
but this is not very elegant, and besides, what if the action we take when N is 2 changes N so that it becomes something else?
Instead we use "otherwise":
otherwise if (a condition)
or…
otherwise unless (a condition)
or…
otherwise (a phrase)
or…
else if (a condition)
or…
else unless (a condition)
or…
else (a phrase)
This phrase can only be used as part of an "if …:" or "unless: …", and provides an alternative block of phrases to follow if the first block isn't followed. Example:
if N is 2:
...
otherwise:
...
When there is only a single phrase we can use the shortened form:
if N is 2, say "Hooray, N is 2!";
otherwise say "Boo, N is not 2...";
We can also supply an alternative condition:
if N is 1:
...
otherwise if N is 2:
...
otherwise if N is greater than 4:
...
At most one of the "…" clauses is ever reached - the first which works out.
If the chain of conditions being tried consists of checking the same value over and over, we can use a convenient abbreviated form:
if (value) is:
This phrase switches between a variety of possible blocks of phrases to follow, depending on the value given. Example:
if the dangerous item is:
-- the electric hairbrush:
say "Mind your head.";
-- the silver spoon:
say "Steer clear of the cutlery drawer."
One alternative is allowed to be "otherwise", which is used only if none of the other cases apply, and which therefore guarantees that in any situation exactly one of the blocks will be followed.
if N is:
-- 1: say "1.";
-- 2: say "2.";
-- otherwise: say "Neither 1 nor 2.";
This form of "if" layout is not allowed to use "begin" and "end" instead of indentation: it would look too messy, and would scarcely be an abbreviation. It is also not allowed to use "unless" instead of "if", because the result would be too tangled to follow.
The next control phrase is "while", which has the form:
while (a condition):
This phrase causes the block of phrases following it to be repeated over and over for as long the condition is true. If it isn't even true the first time, the block is skipped over and nothing happens. Example:
while someone (called the victim) is in the Crypt:
say "A bolt of lightning strikes [the victim]!";
now the victim is in the Afterlife;
We must be careful not to commit mistakes like the following:
while eggs is eggs:
say "again and ";
which, as sure as eggs is eggs (which is very sure indeed), writes out
again and again and again and again and again and ...
forever. (Inform won't prevent this: we will find out the hard way when the story is played.) While we would probably never write anything so blatant as that, the mistake is all too easy to commit in disguised form. We should never design a loop, as repetitions like this are called, without worrying about if and when it will finish.
As with "if", we can use "begin" and "end" instead of a tabulated layout if we want to --
while ...
begin;
...
end while.
(The "begin" of an "if" must of course match an "end if", not an "end while", and so on.)
Experience shows that it is much more legible to lay out "while" loops as blocks, even in these rare cases when only a single phrase forms the body of the block.
The other kind of loop in Inform is "repeat". The trouble with "while" is that it's not obvious at a glance when or whether the loop will finish, and nor is there any book-keeping to measure progress. A "repeat" loop is much more predictable, and is more or less certain to finish.
There are several forms of "repeat", of which the simplest is similar to the old FOR/NEXT loop from the home-computer programming language BASIC, for those with long memories:
repeat with (a name not so far used) running from (arithmetic value) to (arithmetic value)
or…
repeat with (a name not so far used) running from (enumerated value) to (enumerated value):
This phrase causes the block of phrases following it to be repeated once for each value in the given range, storing that value in the named variable. (The variable exists only temporarily, within the repetition.) Example:
repeat with counter running from 1 to 10:
...
This, and runs through the given phrases ten times. Within those phrases, a special value called "counter" has the value 1 the first time through, then the value 2, then 3 and so on up to 10. (It can of course be called whatever we like: this is only an example.) The range can be from any kind where ranges make sense - anything on which arithmetic can be done, so for instance
repeat with moment running from 4 PM to 4:07 PM:
...
and also any enumeration:
Colour is a kind of value. The colours are red, orange, yellow, green, blue, indigo and violet.
...
repeat with hue running from orange to indigo:
...
We are allowed to "nest" loops, that is, to put one inside another.
To plot a grid with size (S - a number):
repeat with x running from 1 to S:
say "Row [x]:";
repeat with y running from 1 to S:
say " [y]";
say "."
If we then write
plot a grid with size 5;
then the result is
Row 1: 1 2 3 4 5.
Row 2: 1 2 3 4 5.
Row 3: 1 2 3 4 5.
Row 4: 1 2 3 4 5.
Row 5: 1 2 3 4 5.
Thus the innermost phrase, the say which mentions "y", happens 25 times.
Whenever dealing with numbers in Inform we may need to remember that if the Settings for the project are set to use the Z-machine, the range is restricted to -32768 up to 32767. Repeating with a counter up to exactly 32767 is hazardous, because the counter can never break through this barrier: it's infinity, so far as Inform is concerned, and that can cause the repetitions to go on forever. (On Glulx, numbers can be very much larger.)
Inform is not used very much for numerical work, so the kind of repeat loop described in the previous section is not much used. Inform's natural domain is really the world of things and rooms, so the following kind of repeat is much more useful.
repeat with (a name not so far used) running through (description of values):
This phrase causes the block of phrases following it to be repeated once for each value matching the description, storing that value in the named variable. (The variable exists only temporarily, within the repetition.) Example:
repeat with item running through open containers:
...
If there are no containers, or they are all closed, the phrases will not be followed at all. Inform will issue a Problem message if the range of the loop may be infinite: for example, it won't allow:
repeat with X running through odd numbers:
...
On the other hand it will allow:
repeat with T running through times:
...
which repeats 1440 times, starting with T at midnight and finishing at 11:59 PM. See the Kinds index for which kinds of value can be repeated through.
As with counting the "number of …" objects satisfying some property, we can run through a wide variety of possibilities - any description whose range is possible for Inform to search. For example:
repeat with dinner guest running through the people in the Dining Room:
...
repeat with possession running through things carried:
...
repeat with event running through non-recurring scenes which are happening:
...
The following lists the whereabouts of all men in lighted rooms:
repeat with suspect running through the men who are in a lighted room:
say "[The suspect] is in [the location of the suspect].";
One small note of caution: if what the "repeat" loop does is to change the things being repeated through, changing in particular whether items not yet reached will qualify to be repeated through, the results can be unexpected. Rather than writing "repeat with X running through D", it may be safer to try "while there is D (called X)", though note that this will only finish if X is always changed so that it no longer qualifies.
So "repeat" and "while" phrases cause a block of other phrases to be repeated, over and over. The number of repetitions and the flow of "control" has so far been controlled only by the way the original loop was described.
But in fact it's also possible to change this from inside the block being repeated, using these:
next
This phrase can only be used inside a "repeat" or "while" block, and causes the current repetition of the block to finish immediately. That either means the next repetition begins, or (if we are already at the last one) the loop ends too. Example:
repeat with X running from 1 to 10:
if X is 4, next;
say "[X] ".
produces the text "1 2 3 5 6 7 8 9 10 ", with no "4" because the "say" phrase was never reached on the fourth repetition.
In Monopoly terms, "next" is "Advance to Go" rather than "go directly, do not pass Go, do not collect $200" - the next iteration begins with the variable, if there is one, having cleanly moved on to the next value, just as if the loop had been run through in the normal way. ("Next" is called "continue" in a fair number of programming languages, so Inform issues a specific problem message to help people who forget this.)
break
This phrase can only be used inside "repeat", "while" block, and causes both the current repetition and the entire loop to finish immediately. Example:
repeat with X running from 1 to 10:
if X is 7, break;
say "[X] ".
produces the text "1 2 3 4 5 6 ", with nothing after "6" because the loop was broken at that point. The "say" wasn't reached on the 7th repetition, and the 8th, 9th and 10th never happened.
Now that it's possible to define phrases where different things are done in different circumstances, we sometimes want to halt early. This is what "stop" is for.
stop
This phrase causes the current rule to end immediately. It is most often used in the definition of other phrases:
To judge the score:
if the score is 0, stop;
say "The score is [score in words] more than it was a half-hour ago."
In the case when the score is 0, the "stop" ends the phrase immediately, so that the subsequent text is printed only if the score is not 0.
"Stop" can also be used in action rules, though this is not very good style - it's clearer to use "stop the action", which is exactly equivalent.
There are sometimes several slightly different ways to perform a given task but which have substantially the same definition. In the following example:
To go hiking, into the woods or up the mountain:
if into the woods, say "Watch out for badgers.";
if up the mountain, say "Better take your compass.";
say "You go hiking."
…a phrase has been set up which can be used in three ways:
go hiking;
go hiking, into the woods;
go hiking, up the mountain;
Note that commas must be used to divide these "phrase options" from the rest of the text of the phrase. Within the definition of the phrase, the option's name is a valid condition, and
if up the mountain, ...
tests whether it is set; we can also test if it is not set using:
if not up the mountain, ...
A more substantial example from the Standard Rules is given by a phrase used mostly for internal, technical reasons:
list the contents of (object)
This phrase produces a list of all things whose holder is the given object, according to Inform's traditional conventions for room descriptions and inventory listings. Example:
list the contents of Marley Wood, as a sentence, with newlines
and including all contents;
Where this is possible, it's generally better to use "[list of things in …]" instead, which produces the same result in an acceptable way for the middle of a sentence.
Note that this phrase is allowed to have multiple options specified, whereas "go hiking" above was not: this is because it was defined thus:
To list the contents of (something - an object), with newlines, indented, as a sentence, including contents, including all contents, giving inventory information, giving brief inventory information, using the definite article, listing marked items only, prefacing with is/are, not listing concealed items, suppressing all articles and/or with extra indentation: ...
The significant difference is the word "and/or" instead of "or", which signals that more than one option can apply at a time.
A variable, as we have seen, is a name for a value which changes, though always remaining of the same kind. For instance, if "target" is a number variable (or "number that varies") then it may change value from 2 to 4, but not from 2 to "fishknife".
To make complicated decisions, phrases often need to remember values on a temporary basis. We have already seen this for the counter in a "repeat" loop, which exists only inside that loop, and then is no longer needed.
We can also make temporary variables using "let":
let (a name not so far used) be (value)
or…
let (a temporary named value) be (value)
This phrase creates a new temporary variable, starting it with the value supplied. The variable lasts only for the present block of phrases, which certainly means that it lasts only for the current rule. Examples:
let outer bull be 25;
let the current appearance be "reddish brown";
let the special room be Marley Wood;
The kinds of these are deduced from the values given, so that, for instance,
say "The outer bull scores [the outer bull in words] when you practice archery in [special room]."
produces
The outer bull scores twenty-five when you practice archery in Marley Wood.
The variable name should be a new one; if it's the name of an existing one, then the kinds must agree. So:
let outer bull be 25;
let outer bull be 50;
is a legal combination, because the second "let" simply changes the value of the existing "outer bull" variable to a different number.
let (a name not so far used) be (name of kind)
This phrase creates a new temporary variable of the given kind. The variable lasts only for the present block of phrases, which certainly means that it lasts only for the current rule. Example:
let inner bull be a number;
The variable created holding the default value for that kind - in this case, the number 0. A handful of very obscure kinds have no default values, and then a problem message is produced. Inform also disallows:
let the conveyance be a vehicle;
because temporary variables aren't allowed to have kinds more specific than "object". (This is a good thing: suppose there are no vehicles in the world?) It's quite safe in such cases to use
let the conveyance be an object;
instead, which creates it as the special object value "nothing".
Temporary variables made by "let" are only temporarily in existence while a phrase is being carried out. Their values often change: we could say
let x be 10;
now x is 11;
for instance, or indeed we could "let x be 10" and then "let x be 11". But although we are allowed to change the value, we are not allowed to change the kind of value. The name "x" must always have the same kind of value throughout the phrase to which it belongs, so the following will not be allowed:
let x be 45;
now x is "Norway";
(The difference between using "let" and "now" here is that "let" can create a new temporary variable, whereas "now" can only alter things already existing: on the other hand, "now" can change many other things as well, whereas "let" applies only to temporary variables.)
We can create new conditions by defining a phrase with "to decide whether" (or equivalently "to decide if"):
To decide whether danger lurks:
if in darkness, decide yes;
if the Control Room has been visited, decide no;
decide yes.
If the player is indeed in darkness, the decision is "yes" because the "decide yes" stops the process right there. We can now write, for instance,
if danger lurks, ...
In fact, "danger lurks" is now a condition as good as any other, and can be used wherever a condition would be given. Rules can apply only "when danger lurks", for instance.
yes
or…
decide yes
This phrase can only be used in the definition of a phrase to decide whether a condition holds. It ends the decision process immediately and makes the condition true.
no
or…
decide no
This phrase can only be used in the definition of a phrase to decide whether a condition holds. It ends the decision process immediately and makes the condition false.
We can also supply definitions of adjectives like this. So far, new adjectives have been defined like so:
Definition: a supporter is occupied if it is described and something is on it.
If we want to give a definition which involves more complex logic, we can use a special form allowing us to make arbitrary decisions. In this longer format, the same definition would look like so:
Definition: a supporter is occupied:
if it is undescribed, decide no;
if something is on it, decide yes;
decide no.
Here "it" refers to the supporter in question. Note that there are now two colons in this sentence, one after "Definition", the other after the clause being defined. But that apart, it's a phrase like any other: it must end in "yes" or "no" just as the "danger lurks" example must. "Decide no" and "decide yes" are needed so often that they can be abbreviated by leaving out "decide":
A condition is a yes/no decision, but we can also take decisions where the result is a value. Suppose we want to create a concept of the "grand prize", which will have different values at different times in play. Each time the "grand prize" is referred to, Inform will have to decide what its value is, and the following tells Inform how to make that decision:
To decide which treasure is the grand prize:
if the Dark Room has been visited, decide on the silver bars;
decide on the plover's egg.
Note that we have to say what kind the answer will be: here it's a kind of thing called "treasure" (which we're supposing has already been created), and as it turns out only two treasures are ever eligible anyway (we're also supposing that the plover's egg and the silver bars are treasures already created, of course). And note also that the phrase must in all cases end with a "decide on …" to say what the answer is:
decide on (value)
This phrase can only be used in the body of a definition of a phrase to decide a value. It causes the calculation to end immediately, with the outcome being the given value, which must be of the kind expected. Example:
To decide which number is double (N - a number):
let D be N times N;
decide on D.
Now that we have "grand prize" created, we can use it just as we would use any other value, so for instance:
if taking the grand prize, ...
As this is something of a dialect difference between English speakers, "what" and "which" are synonymous here, i.e., we could equally well write something like:
To decide what number is the target score: ...
(A phrase to decide if something-or-other is exactly the same thing as a phrase to decide a truth state, and indeed, if we want to then we can use "decide on T", where T is a truth state, in its definition. For instance:
To decide if time is short:
if the time of day is after 10 PM, decide on true;
...
decide on whether or not Jennifer is hurried.
"Decide on true" is exactly equivalent to the more normally used "decide yes", and of course it is optional. The last line is more interesting since it effectively delegates the answer to another condition.)
A piece of ghost-hunting equipment that responds depending on whether or not the meter is on and a ghost is visible or touchable from the current location.
A point which has come up several times in recent chapters is that enumerated kinds of value have a natural ordering. For example, if we write:
Colour is a kind of value. The colours are red, orange, yellow, green, blue, indigo and violet.
…then we not only have seven possible values, we have put them into a sequence, in order of their naming. We can't perform arithmetic on colours, of course, but we can perform comparisons on them. Thus "red < yellow" is true, while "green >= violet" is not. (More on comparisons in the chapter on Numbers and Equations, which also covers arithmetic.)
It's also sometimes useful to get at the sequence directly. First, the two ends:
first value of (name of kind) ⇒ value
This phrase produces the first-created value of the given kind, which should be an enumeration. Example: if we have
Colour is a kind of value. The colours are red, orange, yellow, green, blue, indigo and violet.
then "first value of colour" is red.
last value of (name of kind) ⇒ value
This phrase produces the last-created value of the given kind, which should be an enumeration. Example: if we have
Colour is a kind of value. The colours are red, orange, yellow, green, blue, indigo and violet.
then "last value of colour" is violet.
And now how to step forward and back:
(name of kind) after (enumerated value) ⇒ value
This phrase produces the next-created value of the given kind, which should be an enumeration. Example: if we have
Colour is a kind of value. The colours are red, orange, yellow, green, blue, indigo and violet.
then "colour after orange" is yellow.
(name of kind) before (enumerated value) ⇒ value
This phrase produces the previous-created value of the given kind, which should be an enumeration. Example: if we have
Colour is a kind of value. The colours are red, orange, yellow, green, blue, indigo and violet.