Selecting from a numbered list

I’m starting a project that involves some simple dialog options. My desired behavior is for the player to talk to an NPC, and the NPC’s response will include a numbered list of dialog options (which change based on the game state). Then, the player can just type “1” to use the first option, etc.

So far, I’ve gotten it to list out topics and prompt for a response with this code:

ConversationTopics is a list of text that varies. ConversationTopics is initially {"Test", "Check", "Nevermind"}.

ListingTopics is an action applying to nothing.
Carry out ListingTopics:
	Let TNum be 1;
	repeat with TopicX running through ConversationTopics:
		Say "[TNum]. [TopicX][line break]";
		Increment TNum.

Talking to is an action applying to one visible thing.
Understand "talk to [something]" as talking to.
Check talking to:
	if the noun is not a person, say "[player's forename] can't talk to inanimate objects." instead.

Carry out talking to Steve:
	say "Steve says, 'What's on your mind, [player's forename]?'";
	try ListingTopics;
	now the command prompt is "Choose topic > ".

To decide whether choosing dialog:
	if the command prompt is "Choose topic > ", yes;
	no.

And after that, I’m stuck. I think I need to be able to parse the player’s input and turn it into a number so that I can choose the correct entry from the list of topics, but I can’t get it to work. Any help?

The extension Questions by Michael Callaghan might be what you’re looking for: extensions/Michael Callaghan at 10.1 · i7/extensions · GitHub

3 Likes

Michael Martin’s Quip-Based Conversation and AW Freyr’s Hybrid Choices are the other multiple-choice extensions that folks typically use (I’ve used the former, but not the latter or Questions). But I would agree that you’re probably better off using one of the extensions than creating your own system from scratch; there are all sorts of fiddly edge cases like the player giving invalid input, or keeping track of which options are or aren’t available in particular circumstances, that mean a brand-new implementation is likely to take significant work to get polished.

3 Likes

Thanks for the suggestions. The Questions extension worked perfectly for me.

1 Like