How can I return the contents of a container to the player?

Thanks to @walktothesun,@draconis and @zarf for their answers to my vending machine question about getting the money into the machine (then moved offstage into the coinbox).

Now I’d like to get the money out of the coinbox, as simply as possible. I suppose I could just say “you can’t get your money back” but that feels a bit disingenuous.

Is it possible to write something that would “move the contents of the coinbox to the player” when they perform some action?

This phrasing doesn’t work, but maybe there’s something equally simple to achieve this I’ve been unsuccessful in discovering.

Yes. One option is to loop through the things in the coinbox with the form repeat with ... running through .... (See WI 11.11 for more about repeat running through.)

I’ll show an example here where you can use this phrase to loop through all of the coins in the box and have all of the coins go to the player when the player, let’s say, kicks the coinbox.

Vending area is a room.

the loonie is a thing.
the quarter is a thing.
the dime is a thing.
the nickel is a thing.

The coinbox is in the vending area. The coinbox is a closed, unopenable container.

When play begins:
	move the loonie to the coinbox;
	move the quarter to the coinbox;
	move the dime to the coinbox;
	move the nickel to the coinbox;

Kicking is an action applying to one visible thing. Understand "kick [something]" as kicking.

Carry out kicking the coinbox:
	repeat with coin running through things in the coinbox:
		now the coin is carried by the player;
	say "All of the coins dump out of the coinbox and you pick them all up.".

Output:

Vending area
You can see a coinbox (closed) here.

>i
You are carrying nothing.

>kick coinbox
All of the coins dump out of the coinbox and you pick them all up.

>i
You are carrying:
  a loonie
  a quarter
  a dime
  a nickel

Within this repeat loop, you would have the option to be more precise if you don’t want all of the coins to tumble out of the coinbox by adding conditional statements within the body of the loop. Iteration with this repeat form lets you be precise when needed, but it’s a compact way to evaluate multiple things that share something in common.

The more compact form, if you want all of them, is

	now the player carries everything in the coinbox.
4 Likes

Thank you @walktothesun and @zarf.

They both work perfectly.

Let’s say I wanted to add a complication by having the coins go to a container called returnslot.

I achieved this with the longer version as follows

check pushing coinreturn:
	repeat with coin running through things in the coinbox:
		now the coin is in the returnslot;
	say "With a click and clack your money drops into the return slot.";
	now Paymentdollars is $0.00;
	stop the action.

And with the shorter version as follows

check pushing coinreturn:
	now everything in the coinbox is in the returnslot;
	say "With a click and clack your money drops into the return slot.";
	now Paymentdollars is $0.00;
	stop the action.

Is there any reason one is more robust than the other?

Functionally, not that I am aware of. In this specific case, it is a matter of stylistic preference. However, at the moment you’d need to introduce any further complexity, you will probably want the greater flexibility over the form that is more compact.

This is admittedly far-fetched, but let’s say later you create paper bill currency and the bills somehow find their way into the coinbox. From a flavor text and simulation perspective, you would probably consider whether you want the paper bills occupying the return slot. And if so, you will need to distinguish between coins and paper currency.

But to your point though, there’s no inherent advantage (that I’m aware of) of one form over another when the use case is kept simple like this.