Regarding items in containers, I do this a lot. Here is some sample code from 'Seeker of Magic'. It is probably more complicated than what you need, but you can simplify it to suit your needs. You start out with a tin box. The tin box can be opened and closed. If you examine it when it is initially opened, you can see that it contains a silver key and a parchment. You can take these, providing you have room in your inventory, but you can't put them back again. (This is the only down side.) Note that there is only one boolean used to keep track of the state of the tin box. It uses has_not_created to keep track of whether or not the objects have been removed from the box.
// Tin box
: match "examine box" {
: if (is_present "tin_box") {
: append "It's dark grey and dusty from the ashes. ";
: if (is_box_open) {
:if (has_not_created "silver_key" && has_not_created "parchment") {
: print "It contains a silver <key<13>> and a <parchment<13>>.";
: done;
}
:if (has_not_created "silver_key") {
: print "It contains a silver <key<13>>.";
: done;
}
:if (has_not_created "parchment") {
: print "It contains a <parchment<13>>.";
: done;
}
: print "It's empty.";
: done;
}
: else {
: print "It's closed.";
: done;
}
}
}
: match "open box" {
: if (is_present "tin_box" && is_box_open) {
: print "It's already open.";
: done;
}
: set_true "is_box_open";
:if (has_not_created "silver_key" && has_not_created "parchment") {
: print "It contains a silver <key<13>> and a <parchment<13>>.";
: done;
}
:if (has_not_created "silver_key") {
: print "It contains a silver <key<13>>.";
: done;
}
:if (has_not_created "parchment") {
: print "It contains a <parchment<13>>.";
: done;
}
: print "It's empty.";
: done;
}
: match "close box" {
: if (is_present "tin_box" && !is_box_open) {
: print "It's already closed.";
: done;
}
: set_false "is_box_open";
: print "It's now closed.";
: done;
}
// Key
: match "examine key" {
: if (is_present "silver_key" || (is_present "tin_box" && is_box_open && has_not_created "silver_key")) {
: print "It looks like it's made of silver.";
: done;
}
}
: match "get key" {
: if (is_present "tin_box" && is_box_open && has_not_created "silver_key") {
: if (items_carried() < item_limit()) {
: pocket "silver_key";
: print "You take the <key<13>> out of the tin <box<13>>.";
: done;
}
: else {
: print "You can't carry any more.";
: done;
}
}
}
// Parchment
: match "examine parchment" {
: if (is_present "parchment" || (is_present "tin_box" && is_box_open && has_not_created "parchment")) {
: print "It's dry and brittle and slightly singed around the edges.";
: done;
}
}
: match "get parchment" {
: if (is_present "tin_box" && is_box_open && has_not_created "parchment") {
: if (items_carried() < item_limit()) {
: pocket "parchment";
: print "You take the <parchment<13>> out of the tin <box<13>>.";
: done;
}
: else {
: print "You can't carry any more.";
: done;
}
}
}