The building blocks of coding - objects, properties and verbs

MOO is made up of objects. The first O in MOO stands for Object even. I can't emphasise enough how important objects and 'object oriented'ness is. So what's an object, and what's Object Oriented mean?
Well, as you know, you connect to a player object. You walk around in room objects. You pick up thing objects, and get moved between rooms by exit objects. There's also bulletin board objects, objects for storing useful verbs by category called utility objects, objects for storing commands called feature objects. Lots and lots of objects. The interesting part,(yes I am coming to it!) is how programmers can make objects do something other than what they've already been coded to do.
Each object has an individual reference number so we can tell them apart. This looks like a # followed by some numbers. My Wizard character is #2 for example. The generic surface (gc) is #32.

Objects can store two different types of information. The first is called a 'Property'. In MUSH these are called attributes. Properties are used to store information, generally about the object that they're defined on. They're like little fridge magnets that can hold information underneath them in a particular place so it can be retrieved later. Some extremely common properties are the 'description' property and the 'name' property - they store the description and name of the object respectively.
Properties are refered to by the particular object that the property is storing information on, then a period, then the name of the property. For example, my description is stored in #2.description and my name in #2.name

The other fundamental part of objects is the code that lets you interact with it. Each of these is called a 'Verb' and is stored in a different space than properties, so you can have a verb with the same name as a property. (Actually you can even have two verbs with the same name, but we'll come back to that later) These verbs are written in the MOO programming language, and once you've fixed any bugs in the code and gotten it to compile it'll be written to the object in a special code that the MOO understands. You never need to look at this 'bytecode', you'll always see the MOO code that you wrote.
Verbs are stored on objects, and are refered to in a similar way to properties. First you need the particular object that you want to call the verb on, then a colon ( ':' ), then the name of the verb, then an open bracket then possibly some more information separated by commas (We'll get back to this in more detail later, for now so long as you can regnise a verb that's fine), then a closing bracket. So for example, to call the 'tell' verb on my Wizard, it'd be: #2:tell(). This wouldn't do anything, as we didn't give the verb anything to tell to me. So to give some information to the verb, in this case the text to tell to me, it might be something like #2:tell("Hello Mort."). This would have 'Hello Mort.' appear on my screen if I was connected.

Back up there I said I'd explain what Object Oriented means. What it means is that everything is associated with an object of some sort. Thus the code is oriented towards objects. Not only that, but it includes the concept of 'inheritance'. All objects (apart from 2) have a 'parent' object. Everything that is set on this parent object is inherited by the child object - verbs, properties and even the contents of the properties. This creates a family tree like structure coming down from the base object. A very small chunk of it might be:


            -> Generic Room
            -> Generic Thing  -> Generic Container -> Generic Surface
Root Object                                        -> Generic Clothing
            -> Generic Exit   -> Generic Door
            -> Generic Player -> Generic Builder -> Generic Programmer

Everything that the Root Object has defined on it, is also on the Generic Room, Thing, Exit and Player without having to do anything to put it there. Likewise, the Generic Clothing object inherits all the verbs and properties from the Container, the Thing and the Root Object. In fact, any attempt to put create a new property with the same name as one that is inherited from a parent, will give you an error saying that it is already defined.
Thus, to create a new container all you need to do is create a child of the Generic Container and it will get all of its functionality.


Last modified: Tue Sep 14 23:31:50 GMT 1999