Carry out rules should typically refer to whatever the noun of the player's action was, rather than trying to pick out a specific object. For example:
carry out tomato exchange:
award 5 points;
remove the noun from play;
Since you've already defined the tomato exchange action as applying to "[things]", you don't need any special code to handle batches; if the player says "exchange 3 tomato fruits", your carry out rule will be applied individually to each of three tomato fruits.
Also, a few pointers:
- You can't refer to your tomato fruits as "tomatos" in your code, since that's not how you've defined them. In fact, you can't even refer to them that way in play, since Inform won't understand "tomatos" as a plural of "tomato fruit". You'll need to add something like the following:
a tomato fruit is a kind of thing. understand "tomatos" as tomato fruits.
- You don't need to explicitly tell Inform to announce the score - it will do that automatically whenever the score increases. In fact, a carry out rule generally shouldn't say anything at all, unless your action has very complicated reporting requirements. For a simple pass/fail action, what you really want is a report rule, like so:
report tomato exchange: say "Exchanged."
- You should also use a check rule to make sure that what the player is trying to perform a tomato exchange on is actually a tomato, like so:
check tomato exchange:
if the noun is not a tomato fruit:
say "You can only exchange tomatos!";
stop the action.
- You should explicitly handle what happens when the player types "exchange all". Something like the following should suffice:
rule for deciding whether all includes something which is not a tomato fruit when trying tomato exchange: it does not.
- Finally, the first word of an action name should usually end in "-ing"; this enables a number of convenient shorthands in your code. For example, if your action were named "exchanging tomatos" rather than "tomato exchange", the rule in the preceding point could have been phrased "when exchanging tomatos" rather than "when trying tomato exchange".
EDIT: In the interest of completeness, if you ever do
legitimately need to remove a kind of object from play without reference to whether that object was actually what the player acted upon, you can use the "random" phrase, like so:
remove a random tomato fruit which is in storage from play;
However, I'd strongly recommend against doing so in this case, since the way you've defined your action already picks up the appropriate object (and calls it "the noun").