Inform: Objects Integrated into the Room Description

You often want a significant object to be described as part of the room, instead of showing up at the end of the description. The easy way to do this is by giving the object the scenery attribute.

  
Object Crypt "Crypt"
  with
  description "You are in a gloomy crypt. Everything is stylishly
    gothic, particularly the life-size cardboard cutout of
    Spike which dominates the ambience.",
  has light;

Object -> cutout "cutout"
  with
  name 'cutout',
  has scenery;

   Crypt
You are in a gloomy crypt. Everything is stylishly gothic, particularly the life-size cardboard cutout of Spike which dominates the ambience.

But what if you want the object to be portable? A scenery object can't be picked up.

Solution

To make an object complete disappear from the standard room listing, provide a describe property which does nothing but return true.

(You can't use the initial property for this purpose, because the library prints its own blank line before calling initial. You'd wind up with two blank lines in a row, which is ugly.)

But of course you have to adjust both the room description and the object's describe property, to account for both cases: when the object is present in the room, and when it isn't.

  
Object Crypt "Crypt"
  with
  description [;
    print "You are in a gloomy crypt. Everything is stylishly
      gothic";
    if (cutout in self)
      print ", particularly the life-size cardboard cutout of
        Spike which dominates the ambience";
    ".";
  ],
  has light;

Object -> cutout "cutout"
  with
  name 'cutout',
  describe [;
    if (self in Crypt)
      rtrue;
  ];

   Crypt
You are in a gloomy crypt. Everything is stylishly gothic, particularly the life-size cardboard cutout of Spike which dominates the ambience.

>get cutout
Taken.

>look

Crypt
You are in a gloomy crypt. Everything is stylishly gothic.

>drop cutout
Dropped.

>look

Crypt
You are in a gloomy crypt. Everything is stylishly gothic, particularly the life-size cardboard cutout of Spike which dominates the ambience.

Note that if the cutout is not in the Crypt, its describe does nothing and returns false. This allows it to show up in object lists in the usual way.

Making the integrated message go away permanently

Sometimes you want the object to appear as part of the room, but only until the first time it is moved. For example, a portrait might hang on the wall until you take it; if you drop it again, it goes on the floor.

The initial property is perfectly suited for this, if you don't mind the object's special listing appearing in its own paragraph, after the room description. But if you want them to be integrated, you have to use describe again. This time, we check the moved attribute, instead of the object's location. (The library automatically sets moved whenever an object is carried by the player.)

  
Object Crypt "Crypt"
  with
  description [;
    print "You are in a gloomy crypt. Everything is stylishly
      gothic";
    if (portrait hasnt moved)
      print ", particularly the portrait of LaCroix on the wall";
    ".";
  ],
  has light;

Object -> portrait "portrait"
  with
  name 'portrait',
  describe [;
    if (self hasnt moved)
      rtrue;
  ],
  after [;
    Take:
      if (self hasnt moved)
        "You take the portrait down from the wall.";
  ];

Note that we've also thrown in an after clause, so that the first "take" command produces a special message.

   Crypt
You are in a gloomy crypt. Everything is stylishly gothic, particularly the portrait of LaCroix on the wall.

>get portrait
You take the portrait down from the wall.

>look

Crypt
You are in a gloomy crypt. Everything is stylishly gothic.

>drop portrait
Dropped.

>look

Crypt
You are in a gloomy crypt. Everything is stylishly gothic.

You can see a portrait here.

An integrated message for an object on a table

The describe trick won't work for an object which is on a table (or other supporter).

One simple gimmick is to not put the object on the table at all! Give it an initial message which says that it's on the table. When the player picks it up, the initial message will stop appearing, which is consistent. Unless the table moves to other rooms, the player won't see any real difference.

  
Object Crypt "Crypt"
  with
  description "You are in a gloomy crypt. Everything is stylishly gothic.",
  has light;

Object -> table "table"
  with
  name 'table',
  initial "A table stands in the center of the room.",
  before [;
    Examine:
      <<Search self>>;
    Search:
      if (statuette hasnt moved) {
        print "Resting on the table is a salt statuette 
          of Nancy Crater";
        if (~~child(self))
          ".";
        print ". Beside the statuette";
        WriteListFrom(child(self),
          TERSE_BIT + ENGLISH_BIT + ISARE_BIT);
        ".";
      }
  ],
  has supporter static;

Object -> statuette "statuette"
  with
  name 'statuette',
  initial "A glittering salt statuette of Nancy Crater rests on the 
    table.";

It is nice, for this trick, to customize the table's "search" command. The statuette appears there if it hasn't been moved (whether the table is "really" empty or not.) Once the statuette has been moved, the table defaults to standard "search" routine, which lists all objects (possibly including the moved statuette).

For bonus points, we make the "examine" command synonymous with "search", since there isn't much of interest to the table besides its contents.

   Crypt
You are in a gloomy crypt. Everything is stylishly gothic.

A table stands in the center of the room.

A glittering salt statuette of Nancy Crater rests on the table.

>search table
Resting on the table is a salt statuette of Nancy Crater.

>put wand on table
You put the wand on the table.

>look

Crypt
You are in a gloomy crypt. Everything is stylishly gothic.

A table stands in the center of the room.

On the table is a wand.

A glittering salt statuette of Nancy Crater rests on the table.

>search table
Resting on the table is a salt statuette of Nancy Crater. Beside the statuette is a wand.

>get statuette
Taken.

>search table
On the table is a wand.

>put statuette on table
You put the statuette on the table.

>look

Crypt
You are in a gloomy crypt. Everything is stylishly gothic.

A table stands in the center of the room.

On the table are a statuette and a wand.

>search table
On the table are a statuette and a wand.

An integrated message for an object which is really on a table

If it is necessary that the object really be contained on the table, you will have to delve deeper. I leave the code as an exercise; but the idea is override the "search" command, call WriteListFrom(), and use the WORKFLAG_BIT feature to list everything except the statuette.


More Inform Tricks