Removing an item from play after is has been used?

I am having some difficulty getting this code to work with multiple items. If I only have a single item it will remove just fine, however once I introduced multiple items (duplicates), I can’t seem to get the code to work in my favour.

This is the working code with the troublesome addition in bold:

Section 1 - Firearms

The Shotgun is a thing.
The description of the shotgun is “a single barrel shotgun which requires shotgun shells to use”.

A Bullet is a kind of thing.
A shell is a kind of bullet.

Firing is an action applying to one carried thing.
Understand “fire [shotgun]” as firing.

Before firing the shotgun:
if the player has a shell:
say “Bang!”;
continue the action.

Before firing the shotgun:
if the player does not have a shell:
say “I need ammo”;
stop the action.

After firing the shotgun:
remove a shell from play.

Section 2 - Test Room

The Test Room is a room.

The Shotgun is in the Test Room.

There are ten shells in the Test Room.

How would one best remove a single shell from play after each time the player shoots the gun? I have tried dozens of variations of this one line in an attempt to get it to work but every time i get a compile error. i have tried "remove from the player, remove 1 shell, remove one shell, now the shell is removed from play etc. etc. but i think i have fundamentally missed something.

Could anyone help or point me in the right direction here as I’m a bit lost.

the error i’m getting is:
Problem. You wrote ‘remove a shell from play’ , but ‘a shell’ is used in a context where I’d expect to see a (single) specific example of an object, not a description.

I was trying to match one of these phrases:

  1. remove (a shell - object) from play

  2. remove (a shell - list of values) from (play - list of values)

  3. remove (a shell - value) from (play - list of values)

I recognised:

a shell = a description of shells

But I didn’t recognise ‘play’.

I’m a bit lost on why it says " but ‘a shell’ is used in a context where I’d expect to see a (single) specific example of an object, not a description." as I have defined shells as objects. In gameplay I can pickup any number of the shells or drop any number and it recognises each individually which is why I’m confused as to why it won’t simply remove one of these from play after the action is completed.

Thanks in advance for any help.


Oh man, multiple items can be tricky - I really struggled with this in my first game. Basically what’s going on is “a shell” isn’t specific enough - Inform knows how to move a particular object off-stage, but a general reference to a kind doesn’t give it enough to go on, so the compiler is casting about for alternative explanations for what you wrote.

One illustration of why this isn’t just the compiler being dumb is that your code doesn’t indicate that you want one of the shells carried by the player to be moved off-screen - that’s one example of why it’s helpful that it enforces specificity!

Anyway, try writing the rule this way (I’m on my phone so I haven’t tested this, but pretty sure it should work):

After firing the shotgun:
     Let foo be a random shell carried by the player;
    Remove foo from play.
1 Like

Oh man thanks for the quick reply. I can’t verify this yet but am eager to try it out. So by simply telling it to take a random shell and giving that random shell a reference ‘foo’ in this case (I’m guessing foo could be anything at all e.g. RS for random shell for instance), it then gives the program something more specific even if such thing is in fact random.

I wouldn’t have ever guessed that but it makes sense as a single shell on its own before I made multiples and them a kind of thing was working perfectly.

Cheers, I’ll let you know if this works later on.

1 Like

Yeah, “foo” is an arbitrary label - the “let…” statement basically creates a temporary local variable for the rule. Here’s the documentation: link.

This worked perfectly.

Thanks so much for your help.