Inconsistencies in Q&A processing

I cannot figure out why each time I execute the BUY action, I get different results.
Can someone help me?

"sandbox" by Clyde Falsoon

Include Questions by Michael Callaghan.

Equipment is a kind of thing.
A block is a kind of equipment. An arrow is a kind of equipment.

The Lab is a room. "This is a normal room for conducting experiments.". 
Ten blocks are in Lab. 15 arrows are in Lab.

The player carries 3 arrows.

Does the player mean buying something that is carried by the player: it is very unlikely.
The can't take what's already taken rule does nothing when taking.

QtyQuestion is some text that varies. QtyQuestion is "Great! How many do you want? ".

Instead of buying equipment (called target):
	if the player carries the target:
		say "You don't see any of those for sale." instead;
	now current question is QtyQuestion;
	now the current prompt is " Select from 1 to 10: " ;
	Ask a closed question, in number mode;

A number question rule (this is the get quantity rule):
	if the current question is QtyQuestion:
		let Nbr be the the number understood;
[		say "The number understood = [Nbr][line break]";]
		[Need an extra cycle because 'exit' action throws last one away]
		repeat with N running from 1 to Nbr: 
			try silently taking random block;
		say "Paying for [Nbr] thing[s]: ";
	exit;  [exit discards last step in loop]


test buying with "i/buy block/buy block/buy arrow/i/look".
test Qbuy with "look/i/buy block/3/i/look".


The first two times I get the correct result, but then the third time it is wrong.
Here is another case where it works occasionally.

I think one problem is the line:

try silently taking random block;

You’re not specifying anything about the random block, so a block already carried by the player can be chosen.

You might want to specify random visible uncarried block instead, but be wary of the case when there is no such block.

I include the line

Does the player mean buying something that is carried by the player: it is very unlikely.

Shouldn’t that take care of it?
I’ll try your suggesstion and let you know.

Nope. I get a parser error for the line

 try silently taking random visible uncarried block; 

It doesn’t understand the phrase: visible uncarried block.

“Does the player mean” is specifically about what the player types in. It doesn’t apply to actions that the author specifies in the code.

OK, thanks for that. I kept that line in the code but Im still getting a parser error on the phrase “visible uncarried block;”

The compiler error is because uncarried isn’t a recognized keyword by default.

Either create a definition for it, as in

Definition: A thing is uncarried if it is not carried.

or use the supported-by-default not carried.

Thanks. That is helpful. Seems obvious that not carried is uncarried, like many other properties have that, but then, I beat my head against the obvious. :wink:

I made the same erroneous assumption. It pays to read the Problem messages carefully.

Yeah, Inform specifically does not create “un-” adjectives automatically (though it does make “-er” and “-est” adjectives), because there are so many exceptions where it would get in the way. For example, unliving = not living, but undead ≠ not dead.

So it just leaves it up to the author to define those.