Openable opaque containers

In my current game, I have a number of supporters and containers. The supporters and some of the containers are permanently ‘open’, so you can always examine the contents, get items from the containers and put items in the containers using the techniques described elsewhere in the Adventuron category. One of the containers is openable and transparent, so it is much the same as the others. However, one of the containers is openable and opaque. I found (quite to my surprise) that I could examine the contents of the container when the container was closed. I couldn’t get anything from the closed container, as I already had a check for this using a Boolean variable. I also found that when I was holding the closed container and tried to get something from it, it told me that I was already carrying it, whereas it should have told me that it couldn’t see it.

After much experimenting to work out what was going on, I wrote some debugging code at the top of the on_pre_command{} section so that I could see exactly what Adventuron considered to be in scope:

on_pre_command {
   : match "_ _" {
      : mask {
          : if (is_exists (s1())) {
            : print "^n^exists";
         }
         : if (is_present (s1())) {
            : print "^n^present";
         }
          : if (is_beside (s1())) {
            : print "^n^beside";
         }
          : if (is_carried (s1())) {
            : print "^n^carried";
         }
          : if (is_holding (s1())) {
            : print "^n^holding";
         }
          : if (is_worn (s1())) {
            : print "^n^worn";
         }
      }
   }
}

This indicated that anything in the closed container was still considered to be in scope (i.e. present) if the container was carried or in the room. To work around this in such a way that it worked for any command used on an object in a closed container, I added this little chunk of code near the beginning of on_pre_command{} or on_command{}. In this way, it gave an error response telling me that the hidden object could not be seen. I’m just sharing this in case anyone else has had a similar issue. You just need to check for each of your openable opaque containers (’cookie_box’ in my example) and the boolean variable that indicates whether it’s open or closed (’is_box_open’ in my example). This is just a stop-gap measure until containers are fully supported.

{
   : match "_ _" {
      : if (is_exists (s1()) && parent_of(s1()) == "cookie_box" && !is_box_open) {
         : print {("You can't see any " + original "noun1" + " here.")}
         : done;
      }
   }
}
1 Like

Useful, thanks. I’ve got similar code in a subroutine that checks if S1() is in a closed container and also checks if that container is contained within another container. is_present picks up anything contained or not, is_beside doesn’t pick up contained things, so you can also use that to check if a thing present in the location is contained (present but not carried or beside). Only works for scenery containers though, as is_carried picks up contained, carried things.