Interactive Fiction_3 – Containers

Decorating Your World: Containers
A container is a kind of thing that other portable things can be put into or taken out of.
A wallet, a glass vase, a bowl, a treasure chest, a desk drawer, a backpack, or a paper bag are a few examples of containers that you might want to implement.
Containers have several properties that alter their behavior as well as how the player needs to interact with them.
 
Let’s create a room that has a container object called a paper bag and another thing called a cupcake.
The Foyer is a room. “The Foyer is a drab space containing no furnishings.”
A metal box is a container in the Foyer.  The metal box is scenery.
A cupcake is in the Foyer.  The cupcake is edible.
 .
** By using the line “is scenery“, the player will not be able to take the metal box. 
Another option is to use this code:
The metal box is fixed in place.
 .
Containers are, by default, always open (allowing the player to see what is inside the container) and will be mentioned separately from the room description.
Note: we do not need to provide descriptions for containers
 .
PROPERTIES OF CONTAINERS
Properties for a container object are:
open (is open – but cannot be closed)
closed (is closed but cannot be opened)
openable (is initially open but can be opened and closed by the player)
locked (is locked and closed but can be locked and unlocked as well as opened and closed)
lockable (is initially open but can be locked and unlocked as well as opened and closed)
transparent (the player can always see the contents inside the container whether it is open or closed)
 .
Here is a way to create a cookie jar (that contains a chocolate chip cookie) that starts off being closed but can also be opened and/or closed by the player:
The jar is a closed openable container in the Foyer.
A chocolate chip cookie is in the jar. It is edible.
.
Let’s add another property: transparent.
The glass jar is a closed openable transparent container.
A chocolate chip cookie is in the jar. It is edible.
 .
Now the player will be able to see what is inside the jar even if it’s closed.
Here is how it will look (and behave) in play:
Foyer
This room is a drab place.
You can see a glass jar (closed) (in which is a chocolate
chip cookie) here.
>x jar
In the glass jar is a chocolate chip cookie.
>open jar
You open the glass jar.
>take cookie
You take the chocolate chip cookie.
 .
Let’s take it a step further and lock the jar.
The glass jar is a locked container in the Foyer.
 .
OK, but how can the glass jar be unlocked?
We create a thing called a silver key (that will be initially carried by the player) and state that it can unlock the glass jar:
The silver key is carried by the player. It unlocks the glass jar.
 .
Here is how it will look (and behave) in play:
Foyer
This room is a drab place.
You can see a glass jar (closed) here.
>open jar
It appears to be locked.
>inventory
You are carrying:
a silver key
>unlock jar with silver key
You unlock the glass jar.
>open jar
You open the glass jar.
>take cookie
Taken.
>close jar
You close the glass jar.
>lock jar with silver key
You lock the glass jar.
>
The container object can be a very a complex yet versatile part of your IF work.
 .
THE CARRYING CAPACITY
You may find it necessary to limit the number of things that a container can hold. We can do this by adding the carrying capacity property and assign it a value. For example:
The  metal box is a container in the foyer. The carrying capacity is 1.
 .
Here we have stated that the paper bag can only hold one (1) thing. Any attempts to put more than one thing into the container will result in this message:
>put bread in the box
There is no more room in the metal box.
 .
To change the carrying capacity of any container, simply change the value of the carrying capacity property to any numerical value (2, 3, 4, etc.).
 .
PREVENTING A CONTAINER’S CONTENTS OR STATUS FROM BEING DISPLAYED
Many people wish to prevent containers from displaying their status or their contents in parentheses, include these two lines anywhere in your code:
After printing the name of a container:
omit contents in listing.
 .
These two lines will prevent the status or contents of ANY container from being displayed in parentheses so that the player will have to explicitly examine the container to discover what (if anything) may be inside.
 

____________________________________________________________________________________________________
ASSIGNMENT
After working through the above examples…

Use Inform 7 or www.playfic.com and create:

A simple container.
A locked container (with the key in the room).
A transparent container.
optional – prevent the containers contents from being displayed

Copy and past your working code into notepad and hand in your code.
____________________________________________________________________________________________________

 
This resources is from –  pages 1-6 in the pdf – http://www.hpiweb.com/newmedia/handouts/Decorating%20Your%20World-Containers.pdf

 

Leave A Reply

Your email address will not be published. Required fields are marked *