removing kinds of objects from play.

I have an action where one object needs to be removed. how can I do this when there are multiples of this objects.

this is what I have so far.

[code]tomato exchange is an action applying to one visible thing.

Understand “exchange [things]” as tomato exchange.

carry out tomato exchange:
award 5 points;
say " you have [score] points";
remove one tomato from play.

a tomato fruit is a kind of thing.

10 tomato fruits are in storage.[/code]

Not sure if this will do it, but I do notice that (i) you’ve defined the kind as a “tomato fruit” but the line which should remove a tomato fruit refers only to “one tomato,” and (ii) there’s an extra tab worth of indentation on that line. I assume that “storage” is the name of a room that you’ve previously defined

Robert Rothman

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”).

Thanks david! I knew there was a way to refer to a previously defined noun but I wasn’t sure how!

A quick follow up on the wise words of David J Prokopetz.

You can use “instead” rather than “stop the action”, simplifying the code.

Check tomato exchange: if the noun is not a tomato fruit, say "You can only exchange tomatos!" instead.

Also, this is (officially) deprecated.

award 5 points;

You should use this instead.

increase the score by 5;

See “9.2. Awarding Points” in the inform documentation for further details.

Hope this helps.

thanks that’s a big help!