Miscounting the count of things

I’ve run into another of those things that can’t seem to be fixed in the usual manner.

The Poplar Corner is a room.  The printed name is "In the Poplar Corner". The description is "This is a part of the public park that is the most popular. An apple tree stands nearby."

An apple is a kind of edible thing. The printed name is "ripe apple". The description is "This is a large fruit streaked and flushed with dark red over a background of yellowish-green skin, with spots of russet. It appears ripe and ready to eat." Understand "ripe apple" or "apple" or "fruit" as an apple.

There is an apple in Poplar Corner.

A tree is a kind of enterable scenery supporter. Instead of climbing a tree, try entering the noun.

The Melrose Tree is a tree in the Poplar Corner. The printed name is "apple tree". The description is "This is a tree of ordinary height for the park, but it looks practicaly bush-like next to the poplar tree. [We] can see a reddish fruit hanging from many of the branches. [We]['ve] heard people call it a melrose apple tree." Understand "apple tree" or "melrose" or "tree" as the Melrose Tree.

There are 5 apples on the Melrose Tree.

test me with "take 9 apples / climb tree / take 9 apples".

When you try to take more apples than are available the game generates a parser error. Unfortunately, the response to “take 9 apples” always includes ALL 6 of the apples. I know why the game does it, I just can’t figure out how to fix it.
Why it matters: In my game the tree is narratively full of apples. If you aren’t in the tree, you can only take apples on the ground. All the apples start out on the tree and there’s a random chance each turn that one apple (and only ever one apple) will fall out of the tree. After climbing the tree, you can take only the apples on the tree. That requires stopping the player from taking things on the tree when they aren’t on the tree, and from taking things that aren’t on the tree when the player is on it.
If the player specifies a number of apples to take, and that number is greater than ALL apples in the location, the parser unhelpfully specifies the total number of apples in the room, regardless of accessibility.


Your question is about customizing the parser error message, right?

The crudest option:

Rule for printing a parser error when the latest parser error is the not enough of those available error:
	say "[if number understood is 0]None[otherwise]Not enough[end if] of those are available."

This makes the error message generic for the entire game. That is, it applies to everything, not just apples.

This may be good enough. It’s not a common error message, and players don’t expect much of it.


Just zeroing in on this part, since zarf handled the parser response part of it – your current code doesn’t enforce these restrictions on which apples you can take, since by default the player can access the contents of supporters when they’re in the same location. You might want to consider making trees closed, lit containers instead of supporters, with a climb/enter tree rule that moves the player into the container, since that’ll default to something closer to the scope behavior you want, and in my experience it’s easier to put stuff into scope than to take it out (or just make “up a tree” a separate location and do things that way).


It turns out, the problem has to do with the definition of ALL. Unless you write a rule excluding apples on the tree from ALL, the parser will always report the total number of apples available.

Rule for deciding whether all includes anything on the Melrose Tree:
	if the player is not on the Melrose Tree:
		it does not.

Rule for deciding whether all includes anything not on the Melrose Tree:
	if the player is on the Melrose Tree:
		it does not.

I had the first rule in a previous version of the code, but that only prevents apples on the tree from being counted when the player is not on the tree. You need the second rule to stop the player from being able to take an apple on the ground while they’re up a tree.

1 Like

That catches the case where the player types TAKE ALL (or TAKE ALL APPLES), but note that TAKE APPLE FROM TREE (or just repeated TAKE APPLEs) will still succeed in getting them apples from the tree while they’re on the ground. That may well be close enough but wanted to flag that there are some edge cases with that approach; TAKE ALL is probably 90% of what you need to worry about, so of course it’s up to you whether the game is worth the candle!

Well spotted. I was focused on TAKE ALL, TAKE ALL APPLES and TAKE {a number} APPLES. Taking an apple specifically from the tree has to be stopped in another way:

Definition: a thing (called the item) is out of reach:
	if the player is on a tree and the item is on a tree, no;
	if the player is on a tree and the item is not on a tree, yes;
	if the player is not on a tree and the item is on a tree, yes;

Definition: a thing (called target item) is within reach:
	if the target item is out of reach, no;

Before taking something:
	if the noun is out of reach:
		say "[We] can't reach that.";
		stop the action.

That was basically the code I had, which took care of taking AN apple, but doesn’t apply to ALL or a specified number.

1 Like

And, of course, if there are TWO trees, the given definition of “out of reach” puts the apples on the apple tree within reach of someone halfway up the poplar tree, so you need a better definition:

Definition: a thing (called the item) is within reach:
	if the player is on a supporter (called the spot):
		if the item is on the spot:
		if the item is on a supporter:

Definition: a thing (called the item) is out of reach:
	if the item is within reach, no;

Does the player mean doing something with an out of reach thing: 
	it is very unlikely.
1 Like