Issue with Multiple occurrences of same thing

I’m having a problem with multiple occurrences of the same thing. (like gold pieces). Have not been able to find documentation on the issue. At random (code below), when inserting the gold piece into the slot, am getting error messages, at random. By changing the code below when removing the gold from play, get 2 different messages. For some I get the message ‘gold piece: (first taking the gold piece) Done.’ and for others when I remove the thing from play I get the message ‘gold piece: That isn’t available.’. Not all things are removed from the players inventory. Any help would be appreciated. Thanks in advance.

“Multiple things” by Fyther LaSage

Section - Gold Coins - tokens

A gold piece is a kind of thing. The plural of gold piece is gold pieces. The player carries 50 gold pieces.

The main casino is a room.

The slot machine is a fixed in place device. The slot machine is in the main casino.
The money slot is part of the slot machine. The money slot is an open container.

instead of inserting carried things into the money slot:
if things is gold piece carried by the player:
let GP be a random gold piece carried by the player;
if GP is nothing:
say “You have no more gold to put into the slot machine[line break]”;
else:
[ remove GP from play;]
[ move GP to money slot;]
now GP is nowhere;
[ now GP is off-stage;]
say “(Ding, Ding - 1 coin has been played)[line break]”;
else:
say “You can’t insert the [noun] into the slot of the slot machine. Only gold pieces are allowed!”.

Test me with “I / insert 15 gold pieces in money slot / I”

Multiple things
An Interactive Fiction by Fyther LaSage
Release 1 / Serial number 200526 / Inform 7 build 6M62 (I6/v6.33 lib 6/12N) SD

main casino
You can see a slot machine here.

test me
(Testing.)

[1] i
You are carrying:
fifty gold pieces

[2] insert 15 gold pieces in money slot
gold piece: (Ding, Ding - 1 coin has been played)
gold piece: (Ding, Ding - 1 coin has been played)
gold piece: (Ding, Ding - 1 coin has been played)
gold piece: (Ding, Ding - 1 coin has been played)
gold piece: (Ding, Ding - 1 coin has been played)
gold piece: That isn’t available.
gold piece: (Ding, Ding - 1 coin has been played)
gold piece: (Ding, Ding - 1 coin has been played)
gold piece: (Ding, Ding - 1 coin has been played)
gold piece: (Ding, Ding - 1 coin has been played)
gold piece: (Ding, Ding - 1 coin has been played)
gold piece: (Ding, Ding - 1 coin has been played)
gold piece: (Ding, Ding - 1 coin has been played)
gold piece: That isn’t available.
gold piece: That isn’t available.

[3] i
You are carrying:
thirty-eight gold pieces

1 Like

It would be helpful if you could paste your code using the “preformatted text” option, to preserve indentations. If I copy and paste it as-is, it doesn’t compile.

If a player isn’t carrying something and tries to “insert” it, Inform will usually try to pick the thing up first before trying to insert it. Since your rule as written only runs if the player is already carrying a thing, you may be getting different results based on whether the player was already carrying it or not. I’m guessing that’s what led to the “(first taking the gold piece) Done.” message (and when this happened it probably also failed to remove the gold piece from play).

You could try something like this:

Check inserting something into the money slot when the noun is not a gold piece:
	say “You can’t insert the [noun] into the slot of the slot machine. Only gold pieces are allowed!” instead.

Instead of inserting a gold piece into the money slot:
	now the noun is nowhere;
	say “(Ding, Ding - 1 coin has been played)[line break]”.

I did a quick attempt to debug the code provided, perhaps the results can be helpful. I am on 6M62 compiler. Below is what I came up with, your mileage may vary :slightly_smiling_face:

Section - Gold Coins - tokens

A gold piece is a kind of thing. The plural of gold piece is gold pieces. The player carries 50 gold pieces. 

The main casino is a room.

The slot machine is a fixed in place device. The slot machine is in the main casino.
The money slot is part of the slot machine. The money slot is an open container.

instead of inserting carried things (called player_items)  into the money slot:
	if player_items are gold pieces carried by the player:
		say "you insert the [printed name of player_items] into the machine.[line break]";
		now player_items is nowhere;
	otherwise:
		say “You can’t insert the [printed name of player_items] into the slot of the slot machine. Only gold pieces are allowed!”.

Test me with “I / insert 15 gold pieces in money slot / I”

Running test me repeatedly results in the following with no errors:

main casino
You can see a slot machine here.

>test me
(Testing.)

>[1] i
You are carrying:
  fifty gold pieces

>[2] insert 15 gold pieces in money slot
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.

>[3] i
You are carrying:
  thirty-five gold pieces

>test me
(Testing.)

>[1] i
You are carrying:
  thirty-five gold pieces

>[2] insert 15 gold pieces in money slot
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.

>[3] i
You are carrying:
  twenty gold pieces

>test me
(Testing.)

>[1] i
You are carrying:
  twenty gold pieces

>[2] insert 15 gold pieces in money slot
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.
gold piece: you insert the gold piece into the machine.

>[3] i
You are carrying:
  five gold pieces

>test me
(Testing.)

>[1] i
You are carrying:
  five gold pieces

>[2] insert 15 gold pieces in money slot
Only five of those are available.

>[3] i
You are carrying:
  five gold pieces

>

It might be interesting to learn about multiple action processing rules too if you are dealing with duplicates of items. My first attempt at learning how to deal with duplicates was a challenge! Here is a thread that may be of interest to you:

Thanks for the help. It did exactly what I wanted it to do, but written in a more elegant way. My background is old school mainframe, I keep sliding back into long narratives of code. Again, thanks for the help!

FYI, a slightly more idiomatic way to write this would be:

Instead of inserting something carried into the money slot:
	if the noun are gold pieces:
		say "You insert [the noun] into the machine.[line break]";
		now the noun is nowhere;
	otherwise:
		say “You can’t insert [the noun] into the slot of the slot machine. Only gold pieces are allowed!”.

(Or as bg wrote, you can have separate rules for things in general and gold pieces – the more specific rule wins.)

Note in particular that “the” is part of the substitution as well – this allows it to print the correct thing when a particular object has a different definite article. (There are other adaptations you can do as well, but it’s not usually necessary unless you’re writing an extension that can be used in multiple narrative viewpoints.)