intfiction.org

The Interactive Fiction Community Forum
It is currently Mon Nov 19, 2018 3:51 pm

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Sun Oct 21, 2018 1:15 pm 
Offline

Joined: Sun Oct 21, 2018 10:05 am
Posts: 4
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.

[https://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"


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


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


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sun Oct 21, 2018 2:36 pm 
Offline

Joined: Tue Jan 22, 2008 5:55 am
Posts: 1402
Location: The Netherlands
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:

Code:
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.)


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sun Oct 21, 2018 3:52 pm 
Offline

Joined: Sun Feb 17, 2008 3:51 pm
Posts: 300
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.


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 :)

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

_________________
Skinny Mike


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sun Oct 21, 2018 4:31 pm 
Offline

Joined: Sun Oct 21, 2018 10:05 am
Posts: 4
Thanks! :) 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.

[https://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"


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sun Oct 28, 2018 7:16 am 
Offline

Joined: Sat Oct 17, 2015 5:48 am
Posts: 84
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.


Top
 Profile Send private message  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 15 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group