Taking a single item out of a pile and renaming it

Hello fellow coders,

I have a small beginners problem. My protagonist wears a coat with pockets that contain evidence bags. I want to be able to grab one of them and instantly rename it to “evidence bag 1”. Once you grab another one, this is referred to as “evidence bag 2” and so on. If you put an empty evidence bag into your pocket again, it is removed from play.
How can I do this? Thanks for your help!

Hi,

This sounds like something you can adapt the Pizza Prince example to do… but you also need to count the number of evidence bags you have in play and adjust the printed name when necessary.

So this is what I can come up with, but it’s got some rickety bits:

[code]“Bags of Evidence Bags”

The Lab is a room.

The player wears a coat. A supply of evidence bags is in the coat. Understand “pocket” as the coat. Understand “bag” as the supply of evidence bags.
[this is a bit lazy compared to implementing the pocket separately–having a pocket as part of the coat is possible but will require some special inventory handling]

An evidence bag is a kind of container. An evidence bag has a number called identifier.
The printed name of an evidence bag is “evidence bag [identifier]”. An evidence bag is usually proper-named.

Understand the identifier property as describing an evidence bag. [allows the player to refer to bags as “evidence bag 3” etc.]

The identifier count is initially 1. [creates a variable that keeps track of how many evidence bags we have created.]

Evidence Bag Limbo is a room. Ten evidence bags are in Evidence Bag Limbo.

A clue is a kind of thing. Ten clues are in the Lab.

Instead of taking the supply of evidence bags:
let chosen bag be a random evidence bag in Evidence Bag Limbo;
if chosen bag is nothing: [That is, there were no bags remaining]
say “[too many bags]”;
otherwise:
move the chosen bag to the player;
now the identifier of the chosen bag is the identifier count;
increment the identifier count; [that is, increase it by 1]
say “You take a bag and name it [chosen bag].” [since this happens after changing the identifier of the chosen bag, it will print its new identifier]

To say too many bags:
say “You have too many bags to keep track of. Try emptying one and putting it back in your pocket.”

Rule for implicitly taking the supply of evidence bags:
let chosen bag be a random evidence bag in Evidence Bag Limbo;
if chosen bag is nothing: [That is, there were no bags remaining]
say “[too many bags]”;
otherwise:
move the chosen bag to the player;
now the identifier of the chosen bag is the identifier count;
increment the identifier count; [that is, increase it by 1]
say “(taking [chosen bag] from your pocket)”;
now the noun is the chosen bag.

[Recycling the bags]

Definition: a container (called vessel) is empty if nothing is in the vessel.

After inserting an empty evidence bag into the coat:
move the noun to Evidence Bag Limbo;
continue the action.

[and now we have a bunch of grotty stuff about trying to make sure we interpret the player’s command correctly]

Does the player mean taking a held bag: it is very unlikely.

Does the player mean inserting something into the supply of evidence bags: it is very unlikely.

Does the player mean doing something with an evidence bag (called the first bag) when the player’s command includes “1”:
if the identifier of the first bag is 1, it is very likely.
[/code]

That last line has to do with an issue where the number 1 can be understood as anything whatsoever, so you sometimes have to give the parser an extra nudge to associate the number 1 with the right thing.

Also despite my best efforts, sometimes when you do “take bag/take bag” it decides you mean the bag you just took. I’m not sure what’s going on here–I’m not that good with Does The Player Mean rules.

Anyway I hope this is a good start!

Hey cool, I will have a look into this! Thanks a lot! Maybe I’ll tweak it a little for the case you mentioned.

Uh, there’s a problem: I cannot refer to any evidence bag by its identifier. “Drop evidence bag 1” only asks which of the evidence bag is meant.
What can I do about this?

Oh wait, I made a mistake, sorry.

Ok, I have another question: How can I change the above text to allow “silently taking” (skip the message)?

When do you want to do that? In most cases it’s just a question of eliminating the “say” statement.

If you want to get rid of, or at least improve, some of the automatic messages the game makes when resolving ambiguities you can use a rule for clarifying the parser’s choice of something (§18.30 of Writing with Inform):

Rule for clarifying the parser's choice of the supply of evidence bags while taking: say "(from the supply of evidence bags in your pocket)[command clarification break]".

That gives you:

Ah sorry, I didn’t explain. I programmed an automatic system into the code that will automatically bag items that are marked as evidence. In this xase I don’t want the message from above to appear. From your first solution (the first answer you gave).

You should just be able to copy the code that takes the bag from the coat and take out the “say” line that prints the message.