Any conversation system similar to PAWS but in Inform7?

I am trying to develop a pseudo open system to talk with my NPC´s. Something similar to the games developed in PAWS or DAAD.

I want the parser to be able to recognize key words or the root of key words and then give a message in response. For example, let us say we write “say Helen I want to drive to the coast tomorrow”, then I would like the parser to find key words like “I” “drive” and, ignoring the rest, choose a suitable answer. Is it possible in Inform 7.

Thanks in advance!

1 Like

The example “Complimentary Peanuts” from the Recipe Book at 7.8. Saying Complicated Things implements a form of keyword-based conversation.

This lets the player type dialogue lines/keywords with the NPC name in the beginning, such as: “Helen, I want to drive to the coast tomorrow”.

It also takes care of “ask/tell NPC about …”.

If you additionally want to enable the player to enter “tell Helen I want to drive to the coast” without having to put in an “about” (“tell Helen about I want …”, which wouldn’t sound right), then you could add something like “Understand "tell [someone] [text]" as telling it about.” to that example.

7 Likes

Thank you very much! Very interesting system. I will definitely try how flexible and responsive it is. Do you know if you can pair different key words or is it just one?

2 Likes

You can put several keywords into one topic entry by separating them with slashes: “drive/coast/tomorrow”.

2 Likes

This is great. It is what I was looking for. Very grateful for your help.

2 Likes

The solution is great but, at first sight, I see there are some limitations comparing to PAWS. This method is able to recognize complete words but not the root of a meaning-verb-noun, isn´t it? For example, if you write “ringing” or “ringed” instead of “ring” it doesn´t pick up the common meaning. Or am I wrong?

Also, I would like to recognize pair of words. For example “drive” and “tomorrow” together, but not each word separately. This was easy in PAWS, but in Inform I am struggling to get it done.

1 Like

That’s right. I’m not sure what the most elegant way to approach this would be.

You could either add some of the most common variations to the table with the slash syntax (“ring/ringing/…”).

Or you could use regular expressions (docs: 20.6. Regular expression matching), for example by adding something like this:

Table of Aunt Martha's Regexes
regex	commentary
"\bring.*"	"Test commentary."

Instead of speech when the noun is Aunt Martha:
	repeat through Table of Aunt Martha's Regexes:
		if player's command matches the regular expression regex entry:
			say "[commentary entry][paragraph break]";
			rule succeeds;
	repeat through Table of Aunt Martha's commentary:
		if the topic understood includes topic entry:
			say "[commentary entry][paragraph break]";
			rule succeeds;
	say "'Hmmf,' says Aunt Martha."

(That regex will match “ring” and any number of characters afterwards, like “ringing” or “ring the bell please”, but not “catering”, for example.)

If the system doesn’t find a regex entry, then it goes on to look in the other table with the topic columns which was given in the Complimentary Peanuts documentation example.

I don’t think you can easily combine the regex approach and the topic-column approach into a single table, but someone else might have a more elegant solution. (You could also put everything into the regex table, but I guess that could quickly become a confusing heap of regexes.)

You can do that by using Inform’s “Understand … as …” syntax and by putting the tokens into the topic column of the table, like this:

Table of Aunt Martha's Commentary
topic	commentary
"[drive]"	"'Oh, that's nice.'"

Understand "coast/beach/sea" or "drive tomorrow" as "[drive]".

Relevant docs:

2 Likes

Impressive! Between these two methods I think I can cover more or less everything I want to do with the NPC´s conversations. That is almost as having the best of two worlds, the flexibility of the 80’s parsers in this regard and the might of Inform.

Thank you indeed once again, Mr StJohnLimbo

2 Likes

Just wanted to add that one can of course put the regex into another column in the same table and thus consolidate the code a bit:

Table of Aunt Martha's Commentary
topic	regex	commentary
"[drive]"	"---"	"'Oh, that's nice.'"
"---"	"\bring.*"	"Response to ring, ringing, (etc.)."

Instead of speech when the noun is Aunt Martha:
	repeat through Table of Aunt Martha's commentary:
		if the topic understood includes topic entry or the player's command matches the regular expression regex entry:
			say "[commentary entry][paragraph break]";
			rule succeeds;
	say "'Hmmf,' says Aunt Martha."

… but what I meant in the quoted post was that one can’t really (as far as I know) combine them in an elegant way such that one could put all the keywords to be matched in a single column or combine “Understand” tokens with regexes directly.

2 Likes

That would be nice, but even if this requires a little bit of work, it is good news for me. It is much more than what I was expecting at first. And if sometimes I am a little bit frustrated by Inform, it never ceases to amaze me the things you can do with this extraordinary tool.

I have to fiddle with all these until I can understand the scope of what I can do with it, but it looks promising.

2 Likes

It seems I can pair words in the regex tables. I understood that it wasn´t possible. Quite happy with this.

Table of mayordomo's Regexes
regex				commentary
"limpi.*"				"-No sé si se ha fijado, pero está todo lo limpio que puede estar, fíjese bien. Metafísicamente la suciedad no está sucia, cumple su función. Por otro lado, teniendo en cuenta las circunstancias pragmáticas, sociales, económicas, no creo que esté en condiciones de exigir mucho más de mis servicios. "
"ech.* periodista"				"-No puedo echar a un periodista de la Opacité. Es el cuarto poder y toda mi familia vive sin visado desde hace cinco generaciones. No voy a arriesgarme por usted, señora. Además está la cuestión del parné."
"cuelg.* esp.*"				"-Pero señora, tengo una hernia que no me permite hacer trabajos tan arriesgados"
2 Likes

Yes, you can, that’s no problem! Sorry, I didn’t mean to imply otherwise. :+1:

Further above, I wrote “You could also put everything into the regex table”.

With my later post, I then added a misleading bit when I wrote “one can’t really (as far as I know) combine them in an elegant way such that one could put all the keywords to be matched in a single column” – my bad.
What I meant was “integrating the power of regexes within the simplicity of Inform’s Understand system, or writing topics or Understand tokens which directly employ regexes within them”, something like that.

Regular expressions offer the ultimate flexibility and can work very well.

The only problem that can crop up is that, depending on their complexity, it can sometimes be difficult to tell at a glance what exactly a specific expression will match, and it can relatively easily happen that one writes a regex which matches something different from what one intended, or which misses an unforeseen edge case in the user’s input.

That’s what I meant above when I wrote “(You could also put everything into the regex table, but I guess that could quickly become a confusing heap of regexes.)”, and why I was a bit hesitant to recommend them as the method to use.

There’s a not-quite-serious saying among programmers:

Some people, when confronted with a problem, think “I know, I’ll use regular expressions.” Now they have two problems.

:slight_smile:

But that doesn’t mean one shouldn’t use them. It’s fine if you do it carefully and test them thoroughly.

3 Likes

Not at all, I am struggling to understand all this because it is my first game, you are not to blame for my miscomprehension. Thank you so much for all your help. It means a lot.

As for your recommendation I think it makes all the sense. It was necessary to adapt the code a little bit to admit both systems, but now it seems to work fine. I am aware this comes with some risks, but I prefer some weird responses in a flexible system even if it comes with those.

Now I have the conversation system I was looking for. Jolly god ^^

1 Like