# Is there a way to count the number of a kind?

``````Counting is an action applying to one touchable thing.

Understand "count [something]" as counting.

Report counting a bill:
say "You're carrying [A list of bills carried by the player].  You have [the total price of bills held by the player]."

Report counting something:
say "One!"``````

All right.

Obviously I need to supress the generic reporting, which I want to know how to do too.

Do I need a second verb “counting multiply is an action applying to multiple things” or something bizarre like that?

I tried a bunch of “if the location encloses more than one foo” type of statements and couldn’t make anything work.

I have a feeling I’m missing something easy.

I don’t think you are missing something easy. Making a verb that can apply to multiple objects isn’t so bad; you just have to specify that in the understand line, thus:

``Understand "count [things]" as counting.``

But what happens when you do this is that the action gets performed successively on every object that’s specified. Consider “take all”; first you take one thing, then you take the next, then you take the next, and so on.

What we have to do is design the action so it does everything we want when it’s carried out on the first item in the list, and then it doesn’t do anything for the rest of them. Ex. 420, “The Facts Were These,” is a good example of this sort of thing and describes it thus:

…which gets complicated. I think I’ll have a workingish example pretty soon, but studying example 420 will help.

Example 284 (Left Hand of Autumn) discusses this as well; “[things]” is a token of grammar and covered in 16.4 of the Understanding chapter.

Okay, here’s what I got:

[rant][code]Waiting Room is a room. A bill is a kind of thing. A cost is a kind of value. 2 dollars specifies a cost. A bill has a cost called price. The price of a bill is usually 5 dollars. The player carries two bills.

A mint is a kind of thing. A dish is a container in Waiting Room. Six mints are in the dish.

Counting is an action applying to one touchable thing.

Understand “count [things]” as counting.

Currently counting is a truth state that varies. Currently counting is false.

First check counting:
if currently counting is true:
stop the action. [This is what cuts off the count for the rest of the items on the multiple object list.]

Report counting a bill:
now currently counting is true;
say “You’re carrying [a list of bills carried by the player]. You have [the total price of bills held by the player].[paragraph break]”;
rule succeeds. [This line stops the report counting rulebook, so you don’t fall through to the next rule]

Report counting something:
now currently counting is true; [This sets the flag so we don’t keep doing it]
let L be the multiple object list;
if the number of entries in L is less than 2: [If we’re only counting one thing, then there will be 0 objects in the multiple object list, so we need a special case]
say “One!”;
otherwise:
let T be indexed text; [AFAIK you have to do this to get the word capitalized]
now T is “[the number of entries in L in words]”;
now T is T in sentence case;
say “[T]![paragraph break]”

The before-generation rule is listed before the generate action rule in the turn sequence rules.

This is the before-generation rule: [the documentation for example 420 explains why we need to do it this way]
now currently counting is false.

The selectively announce items from multiple object lists rule is listed instead of the announce items from multiple object lists rule in the action-processing rules.
This is the selectively announce items from multiple object lists rule: [This means that we don’t get a bunch of “mint: mint: mint:” when we’re trying to count]
if counting:
do nothing;
otherwise: [this is just the normal behavior for this rule]
if the current item from the multiple object list is not nothing:
say “[current item from the multiple object list]: [run paragraph on]”.[/code][/rant]

The “multiple object list” is just the list of objects that were specified in the player’s command. All we need to do is figure out how many objects there are in it, which is a simple list operation (not to say that I didn’t have to look up the exact syntax), though it takes some trouble to get it into words with an initial capital letter.

Incidentally, this will lead to odd results if you type “count one bill and two mints” and then “count two mints and one bill.” You might want to make it so you only get the money count if the multiple object list doesn’t contain anything but bills. But that looks like it might be kind of complicated to do (which is to say, I’ve fiddled with it for a bit and I can’t figure out whether there’s a simple way).

This is great and informative. Thank you!

Where has “now T is T in sentence case” been all my life?

In case you’re interested, I worked away at this a little more and added some improvements:

[rant][code]Waiting Room is a room. A bill is a kind of thing. A cost is a kind of value. 2 dollars specifies a cost. A bill has a cost called price. The price of a bill is usually 5 dollars. The player carries two bills.
Bonk is a bill.
A mint is a kind of thing. A dish is a container in Waiting Room. Six mints are in the dish.

Counting is an action applying to one touchable thing.

Understand “count [things]” as counting.
Understand “count [things inside] in/on [something]” as counting it from. Counting it from is an action applying to two things.

Carry out counting it from: try counting the noun instead.

Currently counting is a truth state that varies. Currently counting is false.

To decide whether (fiscal - a list of objects) is monetary:
repeat with item running through fiscal:
if item is not a bill, decide no;
decide yes.

First check counting:
if currently counting is true:
stop the action. [This is what cuts off the count for the rest of the items on the multiple object list.]

Report counting a carried bill:
now currently counting is true;
if the multiple object list is monetary:
say “You’re carrying [a list of bills carried by the player]. You have [the total price of bills held by the player].[paragraph break]”;
rule succeeds. [This line stops the report counting rulebook, so you don’t fall through to the next rule]

Report counting something:
now currently counting is true; [This sets the flag so we don’t keep doing it]
let L be the multiple object list;
if the number of entries in L is less than 2: [If we’re only counting one thing, then there will be 0 objects in the multiple object list, so we need a special case]
say “One!”;
otherwise:
let T be indexed text; [AFAIK you have to do this to get the word capitalized]
now T is “[the number of entries in L in words]”;
now T is T in sentence case;
say “[T]![paragraph break]”

The before-generation rule is listed before the generate action rule in the turn sequence rules.

This is the before-generation rule: [the documentation for example 420 explains why we need to do it this way]
now currently counting is false.

The selectively announce items from multiple object lists rule is listed instead of the announce items from multiple object lists rule in the action-processing rules.
This is the selectively announce items from multiple object lists rule: [This means that we don’t get a bunch of “mint: mint: mint:” when we’re trying to count]
unless counting or counting something from something: [this is just the normal behavior for this rule]
if the current item from the multiple object list is not nothing:
say “[current item from the multiple object list]: [run paragraph on]”.[/code][/rant]

The business about “counting it from” is basically straight out of the “Left Hand of Autumn” example – it means that “count everything in the dish” now gives you the number of things that are in the dish. You’ll notice that when it comes time to carry out counting it from, we just ignore the second noun; it’s in there just to restrict the “all” to the things inside the second noun, as per the Understand line.

Then the definition of a monetary list is there to take care of the thing I mentioned about “count one bill and two mints” – counting bills will only give you the special bill message if you’re exclusively counting bills and if you have at least one bill. If there’s something else in the object list (it’s not a “monetary” list), then that rule doesn’t do anything – in particular, it doesn’t trip the “rule succeeds” condition which ends the rulebook, so it goes on to execute the other report counting rule. I couldn’t figure out a more direct way to express the condition that everything in a given list is a bill.

It looks like I used some chicanery – if you’re carrying a bill and another bill is visible, then which rule gets executed depends on which bill is first in the multiple object list. I think that in this case the carried bill is always going to be first, but in a more general case you probably want to make sure that you do the money count whenever the whole list is bills and there’s a carried bill anywhere in the list.