Storing and Evaluating phrases

I’m currently working on tables for conversations with NPCs and was curious if there was a way to store phrases such as x is 1, preferably within a table, so that I could then see whether or not the phrase stored in the same row of the topic could be evaluated to decide whether that rows response entry would be said. I assume from trying a little bit at this, and not finding anything here or on google about it that it’s not possible but I wanted to ask people who were more familiar to get a definitive answer.

What I’m trying to go for is something like:

Table of Dialogue
Topic Response Statement
"Weather" "I love sunny days." current weather is sunny
"Weather" "I hate the rate." current weather is rainy

To then have something like if statement entry is true or just if statement entry to decide which of the two rows to use.

The main reason I want to store this information in the table to reference is that each npc will have their own table of entries, and so one npc may like the rain and thus have a positive response, and another have a negative, so it wouldn’t work to do a check as part of the action (unless I checked both the weather and person being talked to which I feel would get very unwieldy).

I think that the functionality that you’re looking for doesn’t really exist in the form that you’re looking for, which as I understand it is the ability to put any kind of condition in the column of the table. The closest I can get is a little complex in its construction, and it restricts the phrases that can be used to a single logic type (i.e. having the same number and type of inputs and the same type of output).

"Stored Phrases"

Place is a room.

Moving number is a number that varies.

To decide whether (input - number) is high (this is highballing):
    if input is greater than 5, decide yes;
    decide no.

To decide whether (input - number) is low (this is lowballing):
    if input is at most 5, decide yes;
    decide no.

Table of Observations
Observation	Conditional (phrase number -> truth state)
"That's a great big number."	highballing
"That's a regular number."	lowballing

Every turn:
    now moving number is a random number between 1 and 10;
    say "<moving number set to [moving number]>[line break]";
    repeat through the Table of Observations:
	    if conditional entry applied to moving number is true, say observation entry.

Test me with "z / z / z / z / z / z / z".

A better approach would probably be to set up a rulebook for the purpose of determining responses, which would offer the flexibility to create any preamble conditions that you like, as well as offer more freedom in the nature of responses (e.g. allowing other state to be changed as well as printing text).

2 Likes

Thank you, I’ll try messing around with this a bit to see if it’ll work for what I’m going for. I’ll also take a closer look at rulebooks. My only worry is having lots of characters with lots of different things to talk about (with then different things to say within each topic) could become quite unwieldy. But hopefully I can figure something out.

Depending on the specific use case, you might also, for some parts, get away with having only one entry for the topic, and directly putting the condition inside the text:
"[if the weather is fine]'It's nice, isn't it?'[otherwise]'It's terrible!'[end if]"

Example:

The Hall is a room.

Alice is a woman in the Hall.

To decide if the weather is fine:
	if the time of day is before 9:05 am, yes;
	no.

Instead of asking Alice about a topic listed in the Table of Alice Dialogue:
	say "[reply entry][paragraph break]".
	
Table of Alice Dialogue
topic	reply
"weather"	"[if the weather is fine]'It's nice, isn't it?'[otherwise]'It's terrible!'[end if]"

Test me with "ask alice about weather / z / z / z / z / ask alice about weather".
2 Likes

Thank you. I don’t know why my mind completely skipped over using the if’s within the dialogue. I guess I was just hoping for something a bit easier for me to organize (i usually find the ifs within things to say hard to look at). But I’ll try writing a bit with this as well and see how it works for me.

Since you want characters to be able to speak on multiple topics, I think a table containing rules to be checked is a good way to go here, probably better than rulebooks per se. It gives you an organisational handle on responses to multiple topics, for one character, in one place.

Consider the case of using a straight up rulebook as both the code and the organisational structure, without a table. The rules in it are run in order. You can cancel the process during the rulebook and mark the result as success or failure (if you care about success or failure in Inform’s terms). This way could work handily if you only had one topic. e.g. You’d create a weather rulebook for Tom. First rule checks if weather is sunny, and if it is, says ‘I love sunny days’, and stops the rulebook. If that rule doesn’t fire, second rule checks if weather is rainy, and if it is, says ‘I hate rain.’ And then… what do you want to have happen if neither applies? You may want a fall-through rule that always fires in last place in your weather rulebook. This is something you need to think about, or program, no matter what way you do this.

But what if the player doesn’t want to talk about weather? Well, you might end up making a rulebook like this for each topic for each character. That’s not impossible, but gets into that organisational ickiness you wanted to avoid.

I’ve created an example that shows my approach. Basically, individual rules are checked in an order determined by their appearance in the table, not by grouping them together in a rulebook. If a rule is checked and its conditions match, we end it with ‘rule succeeds’, which results in the corresponding text from the table being printed. If it doesn’t succeed, the next rule for the topic is checked. This continues until a rule activates and prints something, or we’re out of rules, at which point Wendy says she knows nothing about the topic.

Wendy can also be ‘indifferent’ if she’s tapped out on a topic, but I don’t actually make this happen in the example; the conditions causing the topic choices never change, here, and the rules are never deactivated. But I put it in to show how it could work when conditions do change, or when no relevant conditions apply any more for a topic.

This whole thing is kind of a cheapo version of the conversation system in my WIP. I’ve written it around the kind of table you were using, with the response texts in the table. Though consider that if you put the saying of the response text in the rules themselves, you can also run any printing-out code you want in those rules, too, making the mechanism more powerful for producing variable text. And you can put other game-state-changing code in anyway. For instance, when Wendy comments on the sunny weather in the wendy-sunny rule, you could then throw in a flag changing bit of code as part of that rule to set the weather to rainy, and print a message about a storm arriving.

Summary
"Wendy, world's greatest conversationalist. NOT" by Wade.

Cabin is a room.

Wendy is a woman in cabin.

weather is initially 0. [0 is sunny, 1 is rainy, 2 is neither]

the time of day is 7:30 pm.

When play begins:
	say "[italic type]Our story begins at [the time of day]...[roman type][line break]";

table of wendy
topic	response	test condition
"weather"	"I love sunny days."	wendy-sunny rule
"weather"	"I hate the rate."	wendy-rainy rule
"weather"	"I'm ambivalent about the rain."	wendy-weather ambivalent rule
"food"	"It's breakfast time."	wendy-breakfast rule
"food"	"It's lunch time."	wendy-lunch rule
"food"	"DINNER TIME!"	wendy-dinner rule
"life"	"Don't talk to me about life."	wendy-life rule

The block asking rule does nothing.

Check asking wendy about something:
	if the topic understood is not a topic listed in the table of wendy:
		instead say "Wendy says, 'I don't know anything about that.";

Carry out asking wendy about something:
	let SPOKE-FLAG be false;
	repeat through table of wendy:
		if the topic understood matches topic entry:
			follow test condition entry;
			if rule succeeded:
				say "Wendy says, '[response entry]'[line break]";
				now SPOKE-FLAG is true;
				break;
	if SPOKE-FLAG is false:
		say "Wendy looks at you indifferently.";


This is the wendy-sunny rule:
	if weather is 0:
		rule succeeds;

This is the wendy-rainy rule:
	if weather is 1:
		rule succeeds;

This is the wendy-weather ambivalent rule:
	if weather is 2:
		rule succeeds;

This is the wendy-breakfast rule:
	if time of day is before 10 am:
		rule succeeds;

This is the wendy-lunch rule:
	if time of day is before 5 pm:
		rule succeeds;

This is the wendy-dinner rule:
	rule succeeds;

This is the wendy-life rule:
	rule succeeds;

Test me with "ask wendy about dogs/ask wendy about weather/ask wendy about tesseracts/ask wendy about food/ask wendy about life".

-Wade

3 Likes