Inform 7 Home Page / Documentation
§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.
|
ExampleProposal
Asking the player a yes/no question which he must answer, and another which he may answer or not as he chooses.
|
|
Suppose we want to ask the player a question where he might say yes or no in response. There are two possible forms of this: the modal question where the player must pick one to proceed, and the non-modal question where he might also type other verbs.
"Proposal"
The story genre is "A Worked Example about Yes/No Questions".
Section 1 - Asking a Modal Yes/No Question
When play begins:
say "Do you like Mr Spruce? ";
if player consents, now Spruce is handsome;
otherwise now Spruce is ugly;
say paragraph break.
Section 2 - Mr Spruce's Non-Modal Question
Use full-length room descriptions.
The Conservatory is a room. "You are in a room full of plants."
Mr Spruce is a man in the Conservatory. Mr Spruce can be apprehensive or calm. Mr Spruce is calm. Mr Spruce can be handsome or ugly.
At 9:02 AM: say "Mr Spruce flings himself to his knees and implores you to become his lawfully wedded wife.";
now Mr Spruce is apprehensive;
Mr Spruce gives up in two minutes from now.
At the time when Mr Spruce gives up:
say "Mr Spruce sighs heavily, seeing that you don't intend to reply. 'Never mind, my dear, I'll ask later. Perhaps I should have spoken to your Papa first... yes, a gently-bred female... no wonder...'";
now Mr Spruce is calm;
Mr Spruce departs in one minute from now.
At the time when Mr Spruce departs:
if the player can see Mr Spruce, say "Mr Spruce takes his leave of you.";
otherwise say "Mr Spruce pokes his head in to say that he is leaving.";
end the story saying "Well, that is over..."
Instead of saying yes in the presence of an ugly apprehensive Mr Spruce:
now Mr Spruce is calm;
say "Remembering what your mother said to you about the stock exchange and Dear Papa, you close your eyes and accept Mr Spruce.";
end the story saying "Alas for your maiden hopes."
Instead of saying yes in the presence of a handsome apprehensive Mr Spruce:
now Mr Spruce is calm;
say "You are silent with delight for a moment before you say yes, yes!";
end the story saying "How Genevieve Stubbs will cry!"
Instead of saying no in the presence of an ugly apprehensive Mr Spruce:
now Mr Spruce is calm;
say "Gently you inform Mr Spruce that it is impossible. He seems less deflated than you had expected.";
end the story saying "Odd, that..."
Instead of saying no in the presence of a handsome apprehensive Mr Spruce:
now Mr Spruce is calm;
say "You lower your eyes and refuse petulantly, hoping to stir him to a more ardent repetition of these same requests. But then -- alack! -- he says 'I see how it is!' in a strangled voice, and strides from the room!";
end the story saying "A fatal error!"
And since the player might SAY YES TO SPRUCE, we had better reroute the relevant options:
Instead of answering Mr Spruce that "no", try saying no.
Instead of answering Mr Spruce that "yes", try saying yes.
Instead of asking Mr Spruce to try saying yes, try saying yes.
Instead of asking Mr Spruce to try saying no, try saying no.
Instead of saying sorry, try saying no.
Instead of asking Mr Spruce to try saying sorry, try saying no.
Instead of answering Mr Spruce that "sorry", try saying no.
Test me with "z / z / z / yes".
Test more with "z / z / z / no".