Nested Menu in Questions Extension

I’ve been making a game with menu-driven dialog, using the Questions extension by Michael Callaghan. It works well, except when I try to make a nested menu. I want to be able to ask an NPC about multiple categories, with specific topics listed for each category. The top level menu works fine, but the submenus don’t, and I can’t seem to fix it. Here’s an example:

"TestProject" by Spirit
Include Questions by Michael Callaghan.

The library is a room.

Steven is a person. Steven is in the library.

Include Questions by Michael Callaghan.

test me with "talk to steven / 2 / 1".

StevenTopics is a list of text that varies. StevenTopics is initially {"Books", "People", "Nevermind"}.
StevenBooks is a list of text that varies. StevenBooks is initially {"History", "Thrillers", "Fantasy", "Nevermind"}.
StevenPeople is a list of text that varies. StevenPeople is initially {"Matt", "Alice", "John", "Nevermind"}.

Talking to is an action applying to one thing.
Understand "talk to [something]" as talking to.

Carry out talking to Steven:
	say "Steven looks up from his book, looking slightly annoyed. 'What is it now?'";
		now current question is "Ask about:";
		now current question menu is StevenTopics;
		now current prompt is "Choose Topic Number >";
		ask a closed question, in menu mode;

A menu question rule (this is the Steven root conversation rule):
	If the command prompt is "Choose Topic Number >":
		if the number understood is less than 1:
			say "That's not a valid option.[line break]";
			retry;
		else if the number understood is greater than the number of entries in StevenTopics:
			say "That's not a valid option.[line break]";
			retry;
		Let T be the number understood;
		let TopicText be entry T in the current question menu;
		if TopicText is "Nevermind":
			say "Steven shakes his head and mutters as he returns to his book.";
		else:
			try asking Steven about "[TopicText]";
		exit.


After asking Steven about "books":
	say "Steven nods toward the card catalog. 'What genre?'";
		now current question is "Available Books:";
		now current question menu is StevenBooks;
		now current prompt is "Choose a Genre >";
		ask a closed question, in menu mode;


A menu question rule (this is the Steven book conversation rule):
	If the command prompt is "Choose a Genre >":
		if the number understood is less than 1:
			say "That's not a valid option.[line break]";
			retry;
		else if the number understood is greater than the number of entries in StevenBooks:
			say "That's not a valid option.[line break]";
			retry;
		Let T be the number understood;
		let TopicText be entry T in the current question menu;
		if TopicText is "Nevermind":
			say "Steven shakes his head and mutters as he returns to his book.";
		else if TopicText is "History":
			say "Steven recommends The Grapes of Wrath.";
		else if TopicText is "Thrillers":
			say "Steven recommends The DaVinci Code.";
		else if TopicText is "Fantasy":
			say "Steven recommends the Lord of the Rings.";
		exit.


After asking Steven about "people":
	say "Steven raises an eyebrow. 'Who?'";
		now current question is "People:";
		now current question menu is StevenPeople;
		now current prompt is "Who do you want to ask about? >";
		ask a closed question, in menu mode;


A menu question rule (this is the Steven people conversation rule):
	If the command prompt is "Who do you want to ask about? >":
		if the number understood is less than 1:
			say "That's not a valid option.[line break]";
			retry;
		else if the number understood is greater than the number of entries in StevenPeople:
			say "That's not a valid option.[line break]";
			retry;
		Let T be the number understood;
		let TopicText be entry T in the current question menu;
		if TopicText is "Nevermind":
			say "Steven shakes his head and mutters as he returns to his book.";
		else if TopicText is "Matt":
			say "Steven says, 'Matt is friendly but not very reliable.'";
		else if TopicText is "Alice":
			say "Steven says, 'Alice is usually very punctual.'";
		else if TopicText is "John":
			say "Steven says, 'John takes long lunch breaks most days.'";
		exit.

It seems that one way to fix the issue is by changing this line in the “root conversation rule”:

	try asking Steven about "[TopicText]";

… to:

	now command prompt is ">";
	try asking Steven about "[TopicText]" instead;

This worked when I tested it in the given scenario. (NB: after the nested question is handled, the player is returned to the normal command prompt, not to the previous conversation level.)

The important part is the “instead” at the end, by which we stop the current action from proceeding, and do the other action instead. This way, we don’t really do the submenu-question-asking within the previous question’s context, so we can prevent any confusion that the extension’s still-running handling of the previous question might cause otherwise.

The line now command prompt is ">"; is just so that we can get back to the normal command prompt after asking the question. The extension does some internal book-keeping to store and restore the relevant prompts before and after asking questions, and without that line, the book-keeping would restore a wrong prompt.

I haven’t looked too deeply into the Questions extension’s internal workings, but while it’s good at what it does, I think if you’re aiming to do deeper nesting or more complicated conversation menu structures (for example, with players returning to previous nodes), then AW Freyr’s “Hybrid Choices” extension might be a better fit.

(Otherwise, I think you might have to set up quite a number of extra flags and “every turn” rules with the Questions extension.)

2 Likes

Thank you, that worked perfectly.

1 Like