Multiple choice code example

Can someone point me at a multiple choice code example? i.e. print a set of numbered options for the player to choose from, and act on them.

I’ve had a look at the standard example Down in Oodsville, and, sure, I see how that works. However, if you are on the launch platform and decide to step off without choosing a number, that’s OK in Oodsville.

While most of my game is command driven, I want to have the game stop at these decision points, and not continue until the decision is made, and I feel sure this crops up a lot. I’ve scanned all the extensions, and I don’t see it there either.

Thinking about it as I write this, I guess all I’m actually short of is to be able to reject any input other than a number until a valid number appears.

Check out Questions by Michael Callaghan. I didn’t see it in the public library but it’s on the website:

inform7.com/extensions/Michael%2 … index.html

The version of that extension on the website is probably for older versions of Inform. If you want the updated version, try the one at Github:

github.com/i7/archive/blob/mast … stions.i7x

(This is the usual thing with extensions that aren’t in the Public Library–the inform7.com extensions site is for old versions, updated versions wind up at Github, and it’s hard to find this out without a walkthrough.)

EDIT: Actually, I’m not sure there’s any difference between the two versions.

Thanks a lot, both of you.

I won’t be using the extension, but reading the source has clarified my thinking on the matter, and I can see my way ahead.

Here’s a quick demo project showing another way of asking for keypresses in which we leave the parser out of the keypress-asking bit. I’ve used numbers for the options rather than letters because they’re fractionally quicker to handle (with letters you need to check for upper and lower case).

This demo has a bunch of additional keypress routines included in it that it doesn’t use, but which might of use to you so I left them in (and I didn’t write/gather them in the first place, some person called ShadowChaser did.)

The main thing about using the method shown in this demo is that you have to check for matches by using the ASCII/ZSCII numbers of keys, rather than by the key names themselves. I also left in a debug line that you can uncomment to get the raw number for any key.

[rant][code]“Unkind Keypress Demo” by Wade Clarke

Interview Room is a room. “(to run the question routine again, type ROUTINE.)”.

Include Basic Screen Effects by Emily Short.

When play begins:
say “Before you start playing this game… what do you think of this Inform demonstration project so far?[paragraph break]”;
ask the questions.

To ask the questions:
say “(1) It’s okay, I guess.paragraph break The author has a hide to suggest I do things this way.paragraph break This is greatparagraph break I’ve seen better.paragraph break I’ve scraped better code (off the bottom of my shoe)[paragraph break]”;
follow the sensitive question rule.

This is the sensitive question rule:
let NUMBER be the key_pressed;
now NUMBER is NUMBER minus 48; [in the case of integer numbers, the difference between the raw key number and the number key it corresponds to is 48]
[say NUMBER;] [uncomment this line to be able to use this demo to see raw key values every time you press a key]
if NUMBER < 1 or NUMBER > 5:
say “At least have the decency to choose a value in the range I asked for (1-5).”;
instead follow the sensitive question rule;
if NUMBER is 2 or NUMBER is 5:
say “We live in a real world. Come back to it. Please choose again.”;
instead follow the sensitive question rule;
if NUMBER is not 3:
say “That wasn’t a very enthusiastic response. Please choose again.[paragraph break]”;
instead follow the sensitive question rule;
say “That’s the spirit! Now, please enjoy a game devoid of any content. Press < SPACE > to [one of]enter[or]return to[stopping] the mysterious world of the parser…”;
get_the_space_key.

Running the routine is an action applying to nothing.

Understand “routine” as running the routine.

Carry out running the routine:
say “Okay, I’ll ask you again - how do you like this demo so far?[paragraph break]”;
ask the questions.

Book - ShadowChaser’s Useful Functions Extension Excerpts

Part - Keypresses and Space

To decide what number is the key_pressed:
let keypress be 0;
while keypress is 0:
let keypress be the chosen letter;
decide on the keypress.

To decide what number is the key_pressed_with_question (question - some text):
say “[question][line break]”;
decide on the key_pressed.

To get_the_space_key:
let keypress be 0;
while 1 is 1:
let keypress be the chosen letter;
if keypress is 32, make no decision.

To WaitForSpace:
say “[line break]<< Press SPACE to continue >>[run paragraph on]”;
get_the_space_key.

Part - Yes / No

To decide what text is the yesno_answer:
let the answer be “MAYBE”;
let the exitvalue be 0;
while the exitvalue is 0:
let keypress be the key_pressed;
if keypress is 89 or keypress is 121:
let the answer be “YES”;
let the exitvalue be 1;
otherwise if keypress is 78 or keypress is 110:
let the answer be “NO”;
let the exitvalue be 1;
decide on the answer.

To decide what text is the yesno_answer_with_question (question - some text):
say “[question][line break]”;
decide on the yesno_answer.
[/code][/rant]

-Wade

Also AW Freyrs HYBRID CHOICES allows choice lists in a parser game.

Great, severedhand and HanonO! So much help. I must say this is a very friendly supportive forum. Thanks again.