intfiction.org

The Interactive Fiction Community Forum
It is currently Wed Dec 12, 2018 10:37 am

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Wed Jul 04, 2018 1:25 pm 
Offline

Joined: Wed Nov 12, 2008 5:33 am
Posts: 65
Hello fellow coders,

I have a small beginners problem. My protagonist wears a coat with pockets that contain evidence bags. I want to be able to grab one of them and instantly rename it to "evidence bag 1". Once you grab another one, this is referred to as "evidence bag 2" and so on. If you put an empty evidence bag into your pocket again, it is removed from play.
How can I do this? Thanks for your help!


Top
 Profile Send private message  
Reply with quote  
PostPosted: Thu Jul 05, 2018 12:13 am 
Offline

Joined: Tue Mar 09, 2010 2:34 pm
Posts: 5429
Location: Burlington, VT
Hi,

This sounds like something you can adapt the Pizza Prince example to do... but you also need to count the number of evidence bags you have in play and adjust the printed name when necessary.

So this is what I can come up with, but it's got some rickety bits:

Code:
"Bags of Evidence Bags"

The Lab is a room.

The player wears a coat. A supply of evidence bags is in the coat. Understand "pocket" as the coat. Understand "bag" as the supply of evidence bags.
[this is a bit lazy compared to implementing the pocket separately--having a pocket as part of the coat is possible but will require some special inventory handling]

An evidence bag is a kind of container. An evidence bag has a number called identifier.
The printed name of an evidence bag is "evidence bag [identifier]". An evidence bag is usually proper-named.

Understand the identifier property as describing an evidence bag. [allows the player to refer to bags as "evidence bag 3" etc.]

The identifier count is initially 1. [creates a variable that keeps track of how many evidence bags we have created.]

Evidence Bag Limbo is a room. Ten evidence bags are in Evidence Bag Limbo.

A clue is a kind of thing. Ten clues are in the Lab.

Instead of taking the supply of evidence bags:
   let chosen bag be a random evidence bag in Evidence Bag Limbo;
   if chosen bag is nothing: [That is, there were no bags remaining]
      say "[too many bags]";
   otherwise:
      move the chosen bag to the player;
      now the identifier of the chosen bag is the identifier count;
      increment the identifier count; [that is, increase it by 1]
      say "You take a bag and name it [chosen bag]." [since this happens after changing the identifier of the chosen bag, it will print its new identifier]

To say too many bags:
   say "You have too many bags to keep track of. Try emptying one and putting it back in your pocket."


Rule for implicitly taking the supply of evidence bags:
   let chosen bag be a random evidence bag in Evidence Bag Limbo;
   if chosen bag is nothing: [That is, there were no bags remaining]
      say "[too many bags]";
   otherwise:
      move the chosen bag to the player;
      now the identifier of the chosen bag is the identifier count;
      increment the identifier count; [that is, increase it by 1]
      say "(taking [chosen bag] from your pocket)";
      now the noun is the chosen bag.

[Recycling the bags]

Definition: a container (called vessel) is empty if nothing is in the vessel.

After inserting an empty evidence bag into the coat:
   move the noun to Evidence Bag Limbo;
   continue the action.

[and now we have a bunch of grotty stuff about trying to make sure we interpret the player's command correctly]

Does the player mean taking a held bag: it is very unlikely.

Does the player mean inserting something into the supply of evidence bags: it is very unlikely.

Does the player mean doing something with an evidence bag (called the first bag) when the player's command includes "1":
    if the identifier of the first bag is 1, it is very likely.


That last line has to do with an issue where the number 1 can be understood as anything whatsoever, so you sometimes have to give the parser an extra nudge to associate the number 1 with the right thing.

Also despite my best efforts, sometimes when you do "take bag/take bag" it decides you mean the bag you just took. I'm not sure what's going on here--I'm not that good with Does The Player Mean rules.

Anyway I hope this is a good start!


Top
 Profile Send private message  
Reply with quote  
PostPosted: Thu Jul 05, 2018 10:44 am 
Offline

Joined: Wed Nov 12, 2008 5:33 am
Posts: 65
Hey cool, I will have a look into this! Thanks a lot! Maybe I'll tweak it a little for the case you mentioned.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Thu Jul 05, 2018 12:17 pm 
Offline

Joined: Wed Nov 12, 2008 5:33 am
Posts: 65
Uh, there's a problem: I cannot refer to any evidence bag by its identifier. "Drop evidence bag 1" only asks which of the evidence bag is meant.
What can I do about this?


Top
 Profile Send private message  
Reply with quote  
PostPosted: Thu Jul 05, 2018 12:27 pm 
Offline

Joined: Wed Nov 12, 2008 5:33 am
Posts: 65
Oh wait, I made a mistake, sorry.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Fri Jul 06, 2018 7:59 am 
Offline

Joined: Wed Nov 12, 2008 5:33 am
Posts: 65
Ok, I have another question: How can I change the above text to allow "silently taking" (skip the message)?


Top
 Profile Send private message  
Reply with quote  
PostPosted: Fri Jul 06, 2018 9:21 am 
Offline

Joined: Tue Mar 09, 2010 2:34 pm
Posts: 5429
Location: Burlington, VT
When do you want to do that? In most cases it's just a question of eliminating the "say" statement.

If you want to get rid of, or at least improve, some of the automatic messages the game makes when resolving ambiguities you can use a rule for clarifying the parser's choice of something (ยง18.30 of Writing with Inform):

Code:
Rule for clarifying the parser's choice of the supply of evidence bags while taking: say "(from the supply of evidence bags in your pocket)[command clarification break]".


That gives you:

Quote:
>take bag
You take a bag and name it evidence bag 1.

>take bag
(from the supply of evidence bags in your pocket)
You take a bag and name it evidence bag 2.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Fri Jul 06, 2018 9:55 am 
Offline

Joined: Wed Nov 12, 2008 5:33 am
Posts: 65
Ah sorry, I didn't explain. I programmed an automatic system into the code that will automatically bag items that are marked as evidence. In this xase I don't want the message from above to appear. From your first solution (the first answer you gave).


Top
 Profile Send private message  
Reply with quote  
PostPosted: Fri Jul 06, 2018 1:31 pm 
Offline

Joined: Tue Mar 09, 2010 2:34 pm
Posts: 5429
Location: Burlington, VT
You should just be able to copy the code that takes the bag from the coat and take out the "say" line that prints the message.


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

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: Bing [Bot] and 10 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