Seeking a simple way to ask a multiple choice question

Apologies if this has been answered a million times already. My search mostly turned up menu-based dialogue systems, which would be overkill.

I want to ask a single multiple choice question when play begins that I can use to set a value for later use. I haven’t made any headway at all on my own with this. I’m using Inform 7 v10. Can anyone point me in the right direction? Or is this super complicated?

1 Like

I would do it like this:

Lab is a room. "It's a room."

Something can be choosing or tea or coffee or absinthe.
The player is choosing.


Instead of looking when the player is choosing: do nothing.
Rule for printing the banner text when the player is choosing: do nothing.
Rule for constructing the status line when the player is choosing: do nothing.

When play begins:
now the command prompt is "Do you prefer:[line break]1.) Coffee[line break]2.) Tea[line break]3.) Absinthe[line break] >";

After reading a command:
	if the player is choosing:
		if the player's command matches "1" or the player's command matches "coffee":
			now the player is coffee;
			now the command prompt is ">"; 
			move the player to the location;
			reject the player's command;
		otherwise if the player's command matches "2" or the player's command matches "tea":
			now the player is tea;
			now the command prompt is ">"; 
			move the player to the location;
			reject the player's command;
		otherwise if the player's command matches "3" or the player's command matches "absinthe":
			now the player is absinthe;
			now the command prompt is ">"; 
			move the player to the location;
			reject the player's command;
		otherwise:
			say "Please pick 1.) coffee[line break]2. ) tea[line break]3.) absinthe" instead.

Does that help?

4 Likes

I wrote an extension for that™: Inquiry. There’s also Questions by Michael Callaghan.

4 Likes

Thanks both of you. I’ll go experiment and come back later.

Don’t forget about MY favourite method, the “hacky keypress” method.

My eccentricities: I hate having the command line involved in keypress moments at all, so I keep it out of it, using a keypress collection routine from Basic Screen Effects instead. I also don’t like having bits of the question and answer in different places in my source, so I usually dislike extensions and other things that break things up. In Amanda’s approach, I like how the response code is all together, but it’s got the parser involved.

In the following demo, it asks a question at the beginning and stores the answer (1 or 2), then when you JUMP, you get another question. This is just to show how to launch the questions with this method. I set it up to be easy for keypresses from 1-9, but you can use it for alphabet (or any other) keypresses as well, if you want.

"Hacky Keypress Method demo"

Restaurant is a room.

Include Basic Screen Effects by Emily Short.

To decide what number is the key-pressed:
	let keypress be 0;
	while keypress is 0:
		let keypress be the chosen letter;
	now keypress is keypress minus 48;[returns a '1' if player pressed 1, '2' if they pressed 2, etc. If you want to collect/interpret alphabet keys as well, you'd comment out this line, but it makes life easier if all you want to do is collect numbers from 1-9]
	[say "* Keypress number is [keypress].[line break]";][Uncomment this line to see what number the game is seeing when the player presses a particular key.]
	decide on the keypress;

When play begins:
	ask the primal question;
	say "[line break]Btw, When you get a chance, try the command JUMP.";

The primal response is initially 0.[Into this variable, we're going to store the player's answer to the PRIMAL QUESTION as a number. 1 or 2.]

To ask the primal question:
	say "Have you tried Thai food yet?[paragraph break]";
	say "(1) Yes[line break]";
	say "(2) No[paragraph break]";
	while 1 is 1:
		let KEYPRESS be the key-pressed;
		if KEYPRESS > 0 and KEYPRESS < 3:
			say "Thanks for that information.";
			now primal response is KEYPRESS;[store the answer, a 1 or 2, for later, in this variable.]
			make no decision;[ends this keypress loop]

Instead of jumping:
	say "Wait. Did you know that jumping can be dangerous?[paragraph break]";
	say "(1) Yes[line break]";
	say "(2) No[line break]";
	say "(3) Maybe[paragraph break]";
	while 1 is 1:
		let KEYPRESS be the key-pressed;
		if KEYPRESS > 0 and KEYPRESS < 4:
			say "Thanks for that information, which I will not store for future use against you. And now for your jump...";
			make no decision;[ends this keypress loop]

Edit – PS – I wrote this in 6M62, where I have to live for awhile. So if it doesn’t work in version 10, let me know.

-Wade

3 Likes

Thanks all. I’m inclined toward Wade’s and Amanda’s code because they are short and someone of my (low) skill level can read and troubleshoot them.

Both do what I want, but because I’d like to ask the question before the command prompt appears, I’ll go with Wade’s. Thanks very much, everyone!