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?