I would like to let the player choose one item from his inventory to perform an action when asked. I am using the Questions extension by Michael Callaghan. I would like to do something like this:
Instead of taking the gloves:
now the current question is "'What do you want to use to take them?'";
now the current question menu is *the list of things held by the player*;
now the current prompt is "Select a number between 1 and [number of entries in current question menu] >";
now the number understood is 0;
ask a closed question, in menu mode;
follow the gloves rule.
A menu question rule (this is the gloves rule):
if the current question is "What do you want to use to take them?":
if the number understood is 1:
now the player has the gloves;
exit.
Or an alternative might be:
Instead of taking the gloves:
now the current question is "What do you want to use to take them?";
now the current prompt is ">";
ask an open question, in text mode;
follow the gloves rule.
A text question rule (this is the gloves rule):
if the current question is "What do you want to use to take them?":
if the player's command is *a thing held by the player*:
if the player's command matches "feather":
now the player has the gloves;
otherwise:
say "That won't work";
otherwise:
say "You don't have such thing";
exit.
The problem is with code like “list of things held by the player” or “a thing held by the player”. I was also thinking that it might be possible to make a real-time table or list of the inventory, but then you should find a way to update it every time something changes in the inventory.
I am using the 6L38 version. Any idea is really appreciated!
I’ve never worked with this extension. From a quick inspection of it, it looks like the correct way to set the menu options is via:
now the current question menu is <a list of texts>;
It seems like you should be able to construct a list of texts dynamically:
now the current question is "<INSERT QUESTION HERE>";
let CMQ be a list of texts;
repeat with X running through things carried by the player:
add the substituted form of the printed name of X to CMQ;
now the current question menu is CMQ;
ask an open question, in menu mode;
But from there it looks like you have to work with the number understood to determine whether the player picked something suitable, and that seems a little trickier. Perhaps:
if entry (the number understood) of current question menu exactly matches the substituted form of the printed name of the feather:
would work?
I don’t recall whether the substituted form of... phrase was available in 6L38; if not then adjustments may be necessary.
It is; “substituted form” was added the same time indexed text was removed.
Make two lists!
The inventory-list is a list of objects that varies.
…
now the inventory-list is the list of things carried by the player;
repeat with X running through the inventory-list:
add the printed name of X to CMQ;
…
let the chosen item be entry (number understood) of the inventory-list;
Now I only have a final, more general issue. Inform does not include things in containers carried by the player as “things carried by the player”. For example, if the player is carrying a box (carrying a toy) and a lamp, Inform only recognizes the box and the lamp. I would like to make the inventory-list as the list of all things carried by the player and the things carried by containers carried by the player. So that the inventory-list in the example would be: box, toy, lamp.
Use “enclosed by” rather than “carried by”.
EDIT: Ah, Discourse didn’t notify me about new replies this time. Too slow.
There are a lot of ways for one object to be dependent on another: on, in, worn, carried, part of. “Enclosed” simply asks: if one object moves, will the other object move with it? So it encompasses all of these relationships, recursively (if a ticket is in a pocket and the pocket is part of a coat and I’m wearing the coat, I’m not carrying this ticket, but I do enclose it).