Newbie question: keeping track of emptiness of parts?

#1

Hi,
I have an object with a part which is a container that is loaded with expendable “ammunition” I want to keep track of.
For example:

[code]A gun is a kind of thing.
A cartridge is a kind of container. A cartridge is part of every gun. A cartridge is usually closed.
A bullet is a thing.

The Rifle-Range is a room. The rifle is a gun. The rifle is in the Rifle-Range.
In the rifle’s cartridge is a bullet.

[inform7.uservoice.com/forums/57320-general/suggestions/12502053-define-empty-for-containers-and-supporters]
Definition: a container is empty rather than non-empty if the first thing held by it is nothing.

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

Check firing noun when noun is a gun:
if a cartridge is part of the noun:
if the cartridge is empty:
say “You must load ammunition before firing.” instead.

[Ammunition Tracking]
Before firing:
if a cartridge is part of the noun:
Let B be the first thing held by the cartridge;
now B is nowhere;

Report firing:
say “Bang!”

Test me with “take rifle / fire rifle”[/code]

But I can’t get the ammunition tracking part to work- instead I get an error:

[code]Problem. You wrote ‘Let B be the first thing held by the cartridge’ , but ‘cartridge’ 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 this phrase:

first thing held by (cartridge - object)
I recognised:

cartridge = a description of cartridges[/code]

I could probably solve this by not using Parts, but I do want to make it work with them as it is better for the rest of the design.

Thanks!
Ron

0 Likes

#2

The problem is that the game doesn’t know what you mean with “the cartridge”. You need to specify the exact cartridge you mean. I don’t have Inform 7 handy at the moment, but something like this should work:

let current cartridge be a random cartridge part of the noun; if the current cartridge is empty:

instead of the line you have now. (This might fail to compile, I can’t check the exact syntax right now, but this is the basic logic you need.)

0 Likes

(Skinny Mike) #3

Hi Ron,

You just have to let Inform know to which cartridge you’re referring:

[code]Check firing a gun:
if a cartridge (called C) is part of the noun:
if C is empty:
say “You must load ammunition before firing.” instead.

Carry out firing:
if a cartridge (called C) is part of the noun:
let B be the first thing held by C;
now B is nowhere.[/code]

Also, you’re going to want bullets as a kind of thing if you want more than one of them. Also, not sure why you used “before” there – you definitely want “carry out.” HTH :slight_smile:

[edit:]P.S. I don’t know why, but the tabs are screwed up. Sorry.

0 Likes

#4

Thanks! :slight_smile: The code was a little different as you said, but it was the right logic.

This is a working example:

[code]A gun is a kind of thing.
A cartridge is a kind of openable container. A cartridge is part of every gun. A cartridge is usually closed.
A bullet is a kind of thing.

The Rifle-Range is a room. The rifle is a gun. The rifle is in the Rifle-Range.
In the rifle’s cartridge are 2 bullets.

[inform7.uservoice.com/forums/57320-general/suggestions/12502053-define-empty-for-containers-and-supporters]
Definition: a container is empty rather than non-empty if the first thing held by it is nothing.

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

Check firing noun when noun is a gun:
let the current cartridge be a random cartridge which is part of the noun;
if the current cartridge is empty:
say “You must load ammunition before firing.” instead.

Carry out firing noun when noun is a gun:
let the current cartridge be a random cartridge which is part of the noun;
let B be the first thing held by the current cartridge;
now B is nowhere;

Report firing:
say “Bang!”

Test me with “take rifle / fire rifle / fire rifle / fire rifle”[/code]

0 Likes

(Piergiorgio d'errico) #5

Nitpick, last time I checked, cartridge is the brass part of the ammo whose holds the powder, where ammo is stored is called “magazine”, or “cylinder” in case of revolvers…

Best regards from Italy,
dott. Piergiorgio.

0 Likes