What’s with the indexed text hate? I love those little guys.
I was looking to Questions for my own game at first, but it turned out to be overkill for what I needed. Something else I realised in general from playing with it was that, if you seek to make the player type a word and press enter, the only way inform can do that is via the parser. So whenever you wanna lock people off into answering a question by typing-and-entering, your answer must travel through the whole parser mechanism, and you have to block everything else while the question is being answered. I’m not a fan of going the road that unless I have to.
When might you not have to? Well, when the answer doesn’t really need to be typed.
Would you be happy for a menu to appear saying “1 male” and “2” female" and let the player press 1 or 2?
This is an aesthetic decision as well, obviously. You may want the player to type everything and press enter, depending on your game, or you may hate menus, or whatever. But if you’re cool to go the menu route, I definitely prefer it because it creates a bulletproof moment where the player can’t do anything but press 1 or 2, and all the code required to respond to that moment is in one place, not scattered in rulebooks. And it’s easy to understand and program. I agree that Questions can be confusing to deal with.
Below here there’s a bunch of code, so I folded it in a ‘rant’ tag.
[rant]Here’s my code blob which basically sets up this kind of menu. Think of it as the extension:
[code]Include Basic Screen Effects by Emily Short.
The infinite_loop is a number variable. The infinite_loop is 1.
Current question is text variable.
Current question menu is a list of text that varies.
Current question answer is a number variable.
Asking a menu question is a rulebook.
To ask a menu question: follow the asking a menu question rules.
An asking a menu question rule:
while the infinite_loop is 1 begin;
say current question;
say line break;
say fixed letter spacing;
repeat with counter running from 1 to the number of entries in the current question menu begin;
say “[counter] - [entry counter of the current question menu][line break]”;
end repeat;
say variable letter spacing;
let k be 0;
while k is 0 begin;
let k be the chosen letter;
end while;
now k is k minus 48;
now current question answer is k;
if k is less than 1 or k is greater than number of entries in the current question menu, say “[line break]You need to press a number between 1 and [number of entries in the current question menu].[paragraph break]”;
otherwise make no decision;
end while.[/code]
With this in place, here’s how to ask a question:
now current question is "Do you want to be male or female?";
now current question menu is { "Male", "Female" };
ask a menu question;
After the ‘ask a menu question’ line, ‘current question answer’ is the player’s numeric choice. So in this case, it would 1 if they picked male, and 2 if they picked female. The program will not proceed until the player has made a valid choice.
You can have up to 9 choices in your menu in this system. Obviously when it gets to 10, a person can’t type ‘10’ in one keypress.
Here’s a runtime example of the whole thing you can dump in your compiler to see it in action:
[code]Include Basic Screen Effects by Emily Short.
There is a room called Question Arena.
The infinite_loop is a number variable. The infinite_loop is 1.
Current question is text variable.
Current question menu is a list of text that varies.
Current question answer is a number variable.
Asking a menu question is a rulebook.
To ask a menu question: follow the asking a menu question rules.
An asking a menu question rule:
while the infinite_loop is 1 begin;
say current question;
say line break;
say fixed letter spacing;
repeat with counter running from 1 to the number of entries in the current question menu begin;
say “[counter] - [entry counter of the current question menu][line break]”;
end repeat;
say variable letter spacing;
let k be 0;
while k is 0 begin;
let k be the chosen letter;
end while;
now k is k minus 48;
now current question answer is k;
if k is less than 1 or k is greater than number of entries in the current question menu, say “[line break]You need to press a number between 1 and [number of entries in the current question menu].[paragraph break]”;
otherwise make no decision;
end while.
When play begins:
now current question is “Do you want to be male or female?”;
now current question menu is { “Male”, “Female” };
ask a menu question;
say line break;
if current question answer is 1:
say “You chose male.”;
now player is male;
otherwise:
say “You chose female.”;
now player is female.[/code][/rant]
After choosing a sex in the demo, you can verify you really are of that sex by typing ‘showme me’.