??ANSWER TO EXERCISE 82

Note the sneaky way looking through the window is implemented, and that the 'on the other side' part of the room description isn't printed in that case.

Property far_side;
Class  Window_Room
  with description
          "This is one end of a long east/west room.",
       before
       [;  Examine, Search: ;
           default:
             if (inp1~=1 && noun~=0 && noun in self.far_side)
                 print_ret (The) noun, " is on the far side of
                    the glass.";
             if (inp2~=1 && second~=0 && second in self.far_side)
                 print_ret (The) second, " is on the far side of
                    the glass.";
       ],
       after
       [;  Look:
             if (ggw has general) rfalse;
             print "^The room is divided by a great glass window";
             if (location.far_side hasnt light) " onto darkness.";
             print ", stretching from floor to ceiling.^";
             if (Locale(location.far_side,
                    "Beyond the glass you can see",
                    "Beyond the glass you can also see")~=0) ".";
       ],
  has  light;
Window_Room window_w "West of Window"
  with far_side window_e;
Window_Room window_e "East of Window"
  with far_side window_w;
Object ggw "great glass window"
  with name "great" "glass" "window",
       before
       [ place; Examine, Search: place=location;
               if (place.far_side hasnt light)
                   "The other side is dark.";
               give self general;
               PlayerTo(place.far_side,1); <Look>; PlayerTo(place,1);
               give self ~general;
               give place.far_side ~visited; rtrue;
       ],
       found_in window_w window_e,
  has  scenery;
A few words about inp1 and inp2 are in order. noun and second can hold either objects or numbers, and it's sometimes useful to know which. inp1 is equal to noun if that's an object, or 1 if that's a number; likewise for inp2 and second. (In this case we're just being careful that the action SetTo eggtimer 35 wouldn't be stopped if object 35 happened to be on the other side of the glass.) We also need:
[ InScope actor;
   if (actor in window_w && window_e has light) ScopeWithin(window_e);
   if (actor in window_e && window_w has light) ScopeWithin(window_w);
   rfalse;
];

Back to the exercise in section 28
Mechanically translated to HTML from third edition as revised 16 May 1997. Copyright © Graham Nelson 1993, 1994, 1995, 1996, 1997: all rights reserved.