Using Containers

Setting up

A container is an object that can contain other objects, either inside it, or on top of it (a surface).

To set up an object as a container, add the container tag to it. To set up an object as a surface, give it the surface tag.

To add objects to the container or surface, give each of those objects a parent tag specifying the object that contains them.

By default, containers are closed, and so objects inside them won't be revealed (this does not apply to surfaces - surfaces are always open, so you can always see what's on them). To make a container open by default, give it the opened tag.

Here's a simple example of a table. On top of the table is an open bag, and inside that bag is a purse.

define object <table>
	surface
end define

define object <bag>
	container
	opened
	parent <table>
end define

define object <purse>
	parent <bag>
end define

If you run this example you will see that the table and bag are displayed in the room description initially, as both are visible. The purse only becomes visible once the player has looked at the bag. You can tell if the player has looked at a particular object by checking its seen property.

Listing the contents

By default, when a player looks at a container or surface, its contents are listed. You can change this behaviour using the list tags, which allow you to specify if and how contents are listed, and also what message or script to run when the object is looked at and it is either empty or closed. See list tags for more information.

Opening and closing

By default, a closed container can't be opened or closed by the player. To enable this, use the open and close tags. You can either have the object open and close automatically, or you can run some script when the player tries to open or close the object - use this if it is locked, for example.

Putting things and removing things

By default, a player can't put anything on or in a container, or remove anything from it. To allow this, use the add and remove tags.

Note that:

Script commands

You can use the open, close, add and remove script commands to change the setup of containers during the game.

Default responses

You can change the default responses by setting the following error messages: alreadyopen, alreadyclosed, cantopen, cantclose, defaultopen, defaultclose, badput, cantput, defaultput, alreadyput, cantremove, defaultremove.

 

< Back