Page 1 of 1

Looking in a Direction

Posted: Wed Nov 17, 2004 5:26 am
by Cryptonomic
Does anyone have an idea of how I might go about setting up the ability to look in a given direction? For example, if the player were to type "LOOK NORTH", they could be given a description of that. My guess is I would want some property that just displayed a string, like:

north_look = "You see stuff that is to the north."

But I am not certain yet how to go about actually implementing that. I will go through the library files as well and see if I can ferret out an answer for myself but I figured I would try to cover all my bases just in case this is a problem someone ran into before.

Posted: Wed Nov 17, 2004 8:02 am
by Kent
Right now >LOOK WEST will get you something like "You see nothing special to the west", which is generated in objlib.h by the direction class's long_desc property.

You could either handle this specially in a given location's before property as in:

Code: Select all

before
{
     location DoLook
     {
          if object = w_obj
               "...Your description here..."
          else
               return false
     }
}
or, if you wanted to do this throughout the game, you could derive a class from the basic room class and use that to build all your locations. Your derived class could have special handling to do more or less the above for any existing west_desc, etc. properties for the location. Something like:

Code: Select all

room myroom
{
     before
     {
          location DoLook
          {
               if object = n_obj
                    return self.north_desc
               if object = ne_obj
                    return self.northeast_desc
               ...
               else
                    return false
          }
     }
}
(Please note that all this code is untested.)

Note that if, for instance, self.north_desc doesn't exist on the location object, it's the same as returning false in the above code. Your north_desc property, then, would look like:

Code: Select all

north_desc
     "You see stuff that is to the north."
Hopefully that's sort of clear, or at least a start.