Inform 7 Home Page / Documentation
§7.11. Character Knowledge and Reasoning
A character may be endowed with knowledge and even reasoning skills. Relations form quite a good way of keeping track of such problems: for instance, we can allow characters to be acquainted with one another with a relation such as
Or we might keep track of more complicated attitudes between characters, as in Murder on the Orient Express, in which some characters suspect others of the crime.
Alternatively, we might have a list of salient facts that are important in our story. We might declare these as values, and then characters could know, learn, and forget entries as appropriate:
A fact is a kind of value. Some facts are defined by the Table of All Known Facts.
Knowledge relates various people to various facts. The verb to know (he knows, they know, he knew, it is known) implies the knowledge relation.
Table of All Known Facts
fact summary
shoe-size "Lucy wears a size 9 shoe."
sunset-time "Sunset is at 8:22 PM this evening."
Or again we might keep a whole database of information in a table: the characters in Questionable Revolutions know dates, countries, and a short description for each of several rebellions and popular uprisings, while in Queen of Sheba, Solomon is able to answer who, what, where, when, and why questions about a range of topics. This kind of approach is most useful when the characters need to display a deep knowledge of a particular field. The facts stored in the Table of All Known Facts, above, are comparatively sparse, because there we are designing a story in which not all data about the world is equally valuable: Lucy doesn't know the shoe size of every person in the story, because for some reason it is only her own shoe size that matters. On the other hand, the Table of All Known Facts can store different kinds of information, whereas the revolutions table has no way of storing shoe sizes or sunset times. And Murder on the Orient Express works differently again, because it is storing knowledge that concerns people and things that already exist in the world model, rather than abstract ideas. Our way of modeling character knowledge, in other words, will depend quite a lot on what kind of knowledge it is.
The possibilities of character reasoning are similarly broad, but The Problem of Edith introduces one kind: the character has a concept of how different conversation topics relate to one another, so that when she is asked about a new keyword, she picks a response that makes the question most relevant to the conversation already in progress.
We end with a longer scenario, in which we track what the character knows about the player and the conversational state: in Chronic Hinting Syndrome, the main character guides conversation in the direction he intends it to go, with the player's sometimes-reluctant participation.
See Obedient Characters for a character who needs to be taught how to perform actions before doing them
See Characters Following a Script for a programmable robot who can be given whole sequences of actions to perform
Start of Chapter 7: Other Characters | |
Back to §7.10. Character Emotion | |
Onward to §7.12. Characters Following a Script |
ExampleMurder on the Orient Express |
The following example creates two new relations, and two new verbs, in order to set up a tangled web of intrigue.
The Dining Car is a room. Lord Peter is a man in the Dining Car. Sherlock Holmes is a man in the Dining Car. Miss Marple is a woman in the Dining Car. Adam Dalgliesh is a man in the Dining Car.
Dalgliesh suspects Holmes. Holmes suspects Lord Peter. Lord Peter suspects Holmes. Miss Marple suspects the player.
The silver bullet exculpates the player. The pipe ash exculpates Holmes. The poison pen letter exculpates Lord Peter. The poison pen letter exculpates Miss Marple. [Poor Dalgliesh. I guess he did it.]
Given this, we can then set up elaborate rules:
Instead of showing something to a person who suspects the player:
say "'You would say that,' remarks [the second noun] darkly.".
Instead of showing something which exculpates the player to someone:
say "'How striking!' says [the second noun]. 'Almost I begin to distrust myself.'".
Test me with "show the letter to miss marple / show the silver bullet to holmes".
And so on: "if Dalgliesh suspects someone who is exculpated by something carried by the player...", for instance, makes a fitting final example for this chapter. The description
someone who is exculpated by something carried by the player
expresses a complicated idea in very few words, and in such a way that a passer-by looking at the source text would immediately see what was meant.
The moral is that relations allow sophisticated patterns of behaviour to be created in a way that reads back naturally as English.
ExampleThe Problem of Edith |
Suppose that we have a core set of issues we want to be able to bring up with all the characters, and we want characters to draw intelligent connections between different conversation topics. We will need some model of how things relate to one another, so:
Suggestion relates things to each other. The verb to suggest means the suggestion relation.
A subject is a kind of thing. The current subject is a thing that varies. greeting is a subject.
Understand "ask [someone] about [any subject]" as asking it about the subject. Understand "tell [someone] about [any subject]" as asking it about the subject.
Asking it about the subject is an action applying to one thing and one visible thing.
Carry out asking it about the subject:
say "'Hmm, [the second noun],' says [the noun]. ";
relate the current subject with the second noun;
now the current subject is the second noun.
And if we wanted to offer the player some hints about angles he could pursue:
Instead of thinking:
say "You contemplate [a list of things suggested by the current subject]."
For that matter, we could use the same system to have characters make sense of any physical evidence the character shows them:
Instead of showing something which suggests the current subject to someone:
say "[The second noun] nods impatiently."
Instead of showing something to someone:
let the next subject be the next step via the suggestion relation from the noun to the current subject;
if the next subject is a subject:
try asking the second noun about the subject the next subject;
otherwise:
say "[The second noun] shrugs."
When play begins:
now the left hand status line is "Discussing: [current subject]";
now the right hand status line is " ".
Broughton Hall is a room. Lady Uckfield is a woman in Broughton Hall. "Lady Uckfield sits at her desk, looking wholly composed."
The nasty letter is a thing carried by the player. The nasty letter suggests infidelity and penmanship. The ten-pound note is carried by the player. It suggests money.
Infidelity is a subject. Infidelity suggests marriage and divorce. Marriage suggests love. Marriage, love, and divorce are subjects.
Penmanship is a subject. Penmanship suggests education. Education is a subject. Class status and money are subjects. Class status suggests education. Money suggests class status and marriage.
Now we can define what gets said when the subject is changed, regardless of whether the segue was introduced in speech or by a shown object. Since rows are blanked after use, the speaker will never repeat herself; if we provide more than one line about the same pair of topics, the first one will be used, then the second, and so on, until the table runs out:
To relate (initial - a subject) with (next - a subject):
repeat through Table of Remarks:
if the initial is starting entry and the next is the final entry:
say "[comment entry][paragraph break]";
blank out the whole row;
rule succeeds;
say paragraph break.
starting |
final |
comment |
divorce |
love |
"'As it seems to me, all the love is on one side,' she says crisply. 'And that rarely works.'" |
divorce |
love |
"'Stop making that plea: it won't work.'" |
divorce |
infidelity |
"'Frankly, I rather think there would have been cause enough for divorce without the perversely plentiful evidence of unfaithfulness.'" |
divorce |
money |
"'If you mean that the divorce will be expensive, I know it,' she says. 'But I can think of no happier investment.'" |
marriage |
money |
"'If you wish me to understand that it was a marriage for money, you could have spared your energy. That was patent from the outset.'" |
infidelity |
money |
"'I'm sorry, but I don't see how having married for money excuses a subsequent infidelity.'" |
If we had more than one character in the scenario, we could provide multiple tables, but this will do to demonstrate the idea.
Of course, we can override specific instances, if we want the character always to say the same thing regardless of how we came to this point:
Instead of asking Lady Uckfield about the subject penmanship:
now the current subject is penmanship;
say "She sighs. 'So few people write really beautifully these days.'"
Test me with "think / ask lady about infidelity / show nasty letter to lady / show note to lady / think / ask lady about divorce / ask lady about love / ask lady about marriage / ask lady about divorce / ask lady about love / ask lady about penmanship".
We would have to be careful about this system, since we have applied a various-to-various relation to every single object in the game. In practice it would probably be wisest to restrict it a bit, with judicious definitions of kind and so on.
ExampleQuestionable Revolutions |
Interrogative is a kind of value. The interrogatives are who, what, when, where, how, and why.
After asking someone about something: respond to the question. After answering someone that something: respond to the question.
After telling someone about something: say "You're here to ask questions."
Country is a kind of value. The countries are Czechoslovakia, Georgia, Sweden, Italy, Spain.
topic |
date |
place |
definition |
"velvet revolution" |
1989 |
Czechoslovakia |
"A bloodless revolution in Czechoslovakia, in which popular protests led to the resignation of the communist president Gustav Husak, and the election of Vaclav Havel in his place." |
"rose revolution" |
2003 |
Georgia |
"A revolution in which President Eduard Shevardnadze was interrupted by protesters in the middle of his speech, and forced to flee." |
"spanish revolution" |
1936 |
Spain |
"An anarchist and socialist movement during the Spanish civil war." |
After reading a command:
if the player's command includes "[interrogative]", now the current question is the interrogative understood.
To respond to the question:
repeat through the Table of Information:
if the topic understood includes topic entry:
if the current question is what or the current question is who, say definition entry appropriately;
if the current question is when, say date entry appropriately;
if the current question is where, say place entry appropriately;
rule succeeds;
say "[The noun] shrugs."
Comprehension is a kind of value. The comprehensions are vague, erroneous, and correct.
character |
years |
geography |
general comprehension |
Dr Tweedy |
correct |
correct |
correct |
Ms Finch |
erroneous |
erroneous |
correct |
Ms Clarion |
vague |
vague |
erroneous |
When play begins:
say "Here you are in the first class cabin, but no matter how fancy the seats are, you can still get bored circling over Zurich for three hours on end. To kill time, you and the other passengers are playing a trivia game, and the final topic is your specialty: revolutions."
First Class Cabin is a room. Dr Tweedy is a man in First Class. Ms Finch and Ms Clarion are women in First Class.
To say (year - a number) appropriately:
choose row with character of the noun in the Table of Understanding;
if years entry is correct:
say "'[year],' replies [the noun] promptly.";
increment the quiz score of the noun;
if years entry is erroneous:
let guess be a random number between 1900 and 2005;
say "'[guess]?' guesses [the noun], with an air of diffidence[if guess is the year]. Which is right, as it happens[end if].";
if guess is the year, increment the quiz score of the noun;
if years entry is vague:
let offset be a random number between -5 and 5;
let year be year + offset;
say "'I think [year]. About then. Close, anyway,' replies [the noun][if the offset is 0], getting it right[end if].";
if offset is 0, increment the quiz score of the noun.
To say (spot - a country) appropriately:
choose row with character of the noun in the Table of Understanding;
if geography entry is correct:
say "'[spot],' replies [the noun] promptly.";
increment the quiz score of the noun;
if geography entry is erroneous:
let guess be a random country;
say "'Er... [guess]?' says [the noun][if guess is the spot]. Which is of course correct[end if].";
if guess is the spot, increment the quiz score of the noun;
if geography entry is vague, say "'Europe,' replies [the noun] with confidence."
To say (explanation - some text) appropriately:
choose row with character of the noun in the Table of Understanding;
if general comprehension entry is correct:
say "'[explanation]'[paragraph break]";
increment the quiz score of the noun;
otherwise:
choose a random row in the Table of Information;
say "'[definition entry]'[paragraph break]";
if the definition entry is explanation:
say "[A random other person who is not the noun] looks surprised that this came out right.";
increment the quiz score of the noun.
A person has a number called quiz score. The quiz score of Tweedy is 48. The quiz score of Finch is 2. The quiz score of Clarion is 4.
When play begins:
now left hand status line is "T: [quiz score of Tweedy] F: [quiz score of Finch] C: [quiz score of Clarion]";
now right hand status line is "[time of day]".
Test me with "dr tweedy, where was the velvet revolution located / ms finch, when was the rose revolution / ms finch, what was the rose revolution / ms clarion, when was the spanish revolution / g / g / ms finch, when was the spanish revolution".
We have so far seen several ways to write conversational characters in Inform, and we will see more before the end of the manual. This naturally raises the question, which should we use? To which the answer is: it depends on the sort of game we're writing, and what we want our characters to do. The more rich and complex the system, the more likely that it will require a lot of content; if we add question types as well as keywords, for instance, we instantly multiply the number of responses we have to write by five or six. It is not worth doing this unless there is some corresponding advantage within the game.
ExampleThe Queen of Sheba |
Suppose we want the player to ask questions of slightly more complexity - we might want to build in a system that understood "who", "what", "where", and "when", for instance. We could use a topic table for this, too:
Interrogative is a kind of value. The interrogatives are who, what, when, where, how, and why.
After asking someone about something: respond to the question. After answering someone that something: respond to the question.
After telling someone about something: say "You're here to ask questions and test Solomon's wisdom, not to give him a sample of your own."
topic |
question type |
reply |
"rain/weather/clouds/cloud/rains" |
what |
"'Clouds are a disturbance made by the paths of birds,' Solomon replies. 'The air beaten by their wings becomes agitated, as when a river is stirred and the mud churns up.'" |
"rain/weather/clouds/cloud/rains" |
where |
"'Weather is contained in a great silk bag which holds in the heavens,' replies Solomon." |
"hunger/food/eating" |
when |
"'Sorry, are you getting hungry?' he says, and rings a bell to summon servants." |
"hunger/food/eating" |
why |
"'Men were made to need food in order that they must farm and cook and dine together,' Solomon replies. 'Otherwise, they might live apart, each sufficient in himself. But no man can feed himself alone all through his life.'" |
"Solomon/he/himself" |
who |
"'As you see,' he says, holding out his arms to each side." |
"Solomon/he/himself" |
what |
"'I am an ordinary man,' he answers." |
One of the nice things about this system is that it only resets the "current question" when we get a new question word. For instance, this test will produce different replies to the question about Solomon himself, because the second time he is still in the mode of answering "what" questions:
Test me with "ask solomon about himself / ask solomon what rain is / ask solomon about himself".
If Solomon is to live up to his reputation at all, his wisdom table will have to be quite a bit longer - though one also would want to be careful, because forcing the game to cycle through a really immense table could be quite time-consuming. In fact, for the sake of this example, let's reward the player for managing to stay within the (narrow) range of Solomon's knowledge:
The Hall of Almug Tree Pillars is a room. "The pillars of the room are made of almug tree, the ceiling made of silk and the floor of glass." Solomon is a man in the Hall of Almug Tree Pillars. Solomon has a number called wisdom. The wisdom of Solomon is 0.
Every turn:
if the wisdom of Solomon is 3:
say "Truly, Solomon has answered all your questions, and his wisdom is even as great as you had heard!";
end the story saying "Your heart beats strangely fast".
In a real game we'd need to be a great deal subtler. All the same, if we have a character of quite limited resources to present to the player, it's a good idea to give the player some incentive to stay on topic, ask questions the character can answer, and generally interact within the parameters we're prepared for.
Now, this last bit requires some trickery from later chapters, particularly those on Understanding and Activities, to pull the question words out of the player's command:
After reading a command:
if the player's command includes "[interrogative]", now the current question is the interrogative understood.
To respond to the question:
repeat through the Table of Wise Answers:
if the topic understood includes topic entry:
if the current question is the question type entry:
say "[reply entry][paragraph break]";
increment the wisdom of Solomon;
rule succeeds;
say "Solomon looks blank, appalled by a question for which he was not prepared.";
end the story saying "You have befuddled Solomon!"
And now we have a game that will accept (though not always respond very sensibly to) questions of almost any form we might put to another character: ASK SOLOMON WHAT RAIN IS will be answered, but then again, it won't be distinguished from, say, ASK SOLOMON WHETHER THIS PERSISTENT RAIN IS A DIVINE PUNISHMENT OR WHAT.
All the same, a system that allowed the player a bit more specification of questions than simple keyword-use might be useful in a mystery game, for instance, where we might want to let our detective conduct inquiries into specific details. An alternative approach to the rather free one above would be to force the player to use only questions of the form WHAT IS RAIN? or WHO ARE YOU?: this would cut down on false-positive matches. But we might still choose to store the responses in a table of this type.
ExampleChronic Hinting Syndrome |
Suppose we have a conversation system in which it is important to keep track of which subjects the player has heard mentioned. If we're careful to mark subjects in brackets, we can use the "printing the name of" activity to record which things have been mentioned so far:
Knowledge relates various people to various subjects. The verb to know means the knowledge relation.
Awareness relates various people to various subjects. The verb to be aware of means the awareness relation.
Definition: a subject is pending if the player is aware of it and it is not known by the player.
Instead of thinking:
if the number of pending subjects is 0, say "You have no fresh leads at the moment.";
otherwise say "You recall that thus far you have not followed up with questions about [the list of pending subjects]."
After printing the name of a subject (called idea):
now the player is aware of the idea.
Now suppose that as an added convenience for the player, we let him turn on a mode in which useful conversation topics are always automatically highlighted in the text, so he doesn't waste his time trying to follow up dead leads:
Setting is a kind of value. The settings are bright and dull. Understand "on" as bright. Understand "off" as dull.
Highlighting is a setting that varies. Highlighting is dull.
Understand "highlighting [setting]" as setting highlighting. Setting highlighting is an action out of world, applying to one setting.
Carry out setting highlighting:
now highlighting is the setting understood.
Report setting highlighting:
say "Highlighting is now [if highlighting is dull]off[otherwise]on[end if]."
Before printing the name of a subject (called idea) when highlighting is bright:
unless the player knows the idea:
say "[bold type]".
After printing the name of a subject when highlighting is bright:
say "[roman type]".
...And the rest is peripheral.
The Sickbay is a room. "A place arranged for Nathan's comfort, since his sickness has been prolonged and because he becomes so irritating when not comfortable." The Hallway is outside from the Sickbay.
A supporter can be untried or rejected. A supporter is usually untried.
The Sickbay contains a wobbly pedestal, a table, and a sickbed. Understand "bed" as the sickbed. The pedestal, the table, and the sickbed are supporters. Nathan is a man on the sickbed. The sickbed is scenery. The initial appearance of the wobbly pedestal is "A wobbly pedestal near the door has sometimes been known to support vases of flowers, but is currently bare." The initial appearance of the table is "There is also a table of a more ordinary sort."
Instead of putting the sculpture on the table:
now the table is rejected;
say "'[Not there],' [Nathan] snaps. 'The table is way too far from the sickbed.'"
Instead of putting the sculpture on the sickbed:
now the sickbed is rejected;
say "'[Not there],' [Nathan] rebukes you. 'You don't want me knocking it over if I roll around. In pain.'"
Instead of putting the sculpture on the pedestal:
now the pedestal is rejected;
say "The pedestal starts to wobble so ominously that you don't dare let go.
'[Not there],' says [Nathan]. 'That thing is falling apart.'"
Before putting something on the down: try dropping the noun instead.
To say not there:
if all the supporters are rejected:
say "Look, the floor would be fine";
otherwise if the number of rejected supporters is 1:
say "Yeah, anywhere but there, I'm afraid";
otherwise:
say "Come on, use your head -- I can't be watching you all the time, I'm sick".
Instead of going outside when the player is carrying the sculpture:
say "You've still got this sculpture to get rid of."
Instead of going outside when the breakage is pending:
say "You can't very well smash in front of [Nathan] his prize sculpture and then just scamper off without saying something. Appealing though the thought is at the moment."
Instead of going outside when a subject which is not the breakage is pending:
say "'Yeah, go ahead,' says [Nathan], with a martyr-like air. 'It's probably best that you don't hear about [the random pending subject]. It's not something I'd go into normally.'"
The breakage is a subject. The description is "It's not a big deal. I'll just buy a new [mental wave generator].' A slight awkward pause. 'I mean, this one was a [gift], but don't worry about it". Understand "accident" or "smashing" or "breaking" or "shard" or "mishap" or "shards" or "mistake" as the breakage. Understand "sculpture" as the breakage when the player is not carrying the sculpture.
Instead of saying sorry in the presence of Nathan when the player is aware of the breakage:
try asking Nathan about the matter of breakage.
Instead of asking Nathan to try saying sorry when the player is aware of the breakage:
try asking Nathan about the matter of breakage.
The mental wave generator is a subject. The description is "They're kind of expensive but I can save up. I really need one, though, because of my [dreams]".
The dreams is a subject. The description is "They're not the kind of dream you want to have.' He closes his eyes and contemplates these undesirable dreams. 'Have you ever woken up convinced you were dead? No, probably not. Well... At any rate, I need the [generator]. Oh, don't worry, they're expensive but not so expensive that I won't be able to save up for another, in a few months".
The gift is a subject. The description is "[The mental wave generator] was a present from a girl named [Shari]. Actually I'm not sure she'd take to being called a girl".
Shari is a subject. The description is "Look, let's just not go into it, okay? I don't really want to relive all that right now. I still have a six-inch [scar] shaped like a banana in the middle of my back".
Instead of asking Nathan about the matter of the scar:
say "Nathan clears his throat, lowers his voice, and begins to tell you the story...";
end the story saying "End of Demo -- Register to Continue!!"
Understand "ask [someone] about [any subject]" as asking it about the matter of.
Asking it about the matter of is an action applying to one thing and one visible thing.
Check asking it about the matter of:
if the player is not aware of the second noun, say "What [second noun]?" instead;
if the noun does not know the second noun, say "'I've no idea,' replies [the noun]." instead;
if the player knows the second noun, say "You've already covered that. The response was '[description of the second noun].'" instead.
Carry out asking it about the matter of:
now the player knows the second noun.
Report asking it about the matter of:
say "'[description of the second noun],' says [the noun]."
Instead of telling Nathan about something:
say "He pinches the bridge of his nose. 'I can't really follow this right now,' he says. 'I'm sorry.'"
Instead of asking Nathan about something:
say "He shrugs weakly."
When play begins:
say "'Just put that down anywhere,' says [Nathan], as you come into the room. He's sitting in the sickbed with his legs straight out in front of him. 'I don't care where.' His voice is weak, but it sharpens up for the last remark: 'And don't make a lot of noise about it.'
Considering that he woke you from a sound slumber to beg you to bring this thing over, his attitude is a bit much. You stare dubiously at the awkward crystal sculpture in your hands.";
now Nathan knows every subject.
Instead of asking Nathan about something while the player carries the sculpture, say "[Nathan] moans dramatically and refuses to be drawn into conversation."
The player is carrying an awkward crystal sculpture. Understand "objet" or "objet de hideous" as the sculpture. The description of the sculpture is "It might possibly be natural, or it might be man-made. It might appeal to someone, but it is certainly not to your tastes."
Instead of showing the sculpture to Nathan:
say "'Please put it anywhere,' he says."
Instead of giving the sculpture to Nathan:
say "'No, it doesn't work if I touch it. That's why I couldn't-- well, just put it down.'"
After dropping the sculpture:
now the player is aware of the breakage;
now the sculpture is nowhere;
say "You are incredibly careful, but somehow the sculpture slips -- you might almost say slithers -- from your fingers and crashes into a thousand shards at the feet of [Nathan].
Every turn while not asking:
if Nathan is passive, rule succeeds;
if the player is carrying the sculpture:
if showing or giving, rule succeeds;
say "[Nathan] opens one eye and stares at you meaningfully. He is waiting for you to deposit his objet de hideous somewhere.";
rule succeeds;
if the breakage is pending:
if dropping, rule succeeds;
say "You're not quite sure where to begin, but you can't very well leave without making at least some remark on the smashing of the sculpture.";
rule succeeds;
if a subject is pending:
choose a random row in the Table of Offhand Reminiscences;
say "[line entry][paragraph break]".
Table of Offhand Reminiscences
line
"'It actually is kind of a funny story about [the random pending subject],' [Nathan] remarks casually."
"[Nathan] chuckles under his breath. 'Man, I hadn't thought about [the random pending subject] in ages.'"
"He glances sideways at you. 'It's nothing personal, you know, but I don't feel comfortable discussing [the random pending subject] with just anyone.'"
"'I don't know why I brought up [the random pending subject] just now,' [Nathan] comments. 'Don't mention it to anyone, if you don't mind.'"
"'Okay, see, the thing about [the random pending subject] is...' [paragraph break]'Yes?' you ask, on cue.[paragraph break]'...never mind.'"
"[Nathan] makes an explosive exasperated sound. 'Don't you want to ask me about [the random pending subject]?' he demands."
Test me with "highlighting bright / put sculpture on pedestal / put it on table / put it on sickbed / drop it / think / ask nathan about breakage / think / ask him about generator / ask him about dreams / ask him about gift / ask him about shari / ask him about scar".