external next up previous contents index
Next: 8.4 MOO tutorialLevel Up: Basic MOO Programming Tutorial Previous: Procedural/structural Programming

8.3 MOO tutorial, Level 0 (``computer'')

   

(under construction since nov 28 1996, not user tested yet)

Let's program a very simple object just for the fun of it. It will not do anything useful, but teach you a few basic things. You will not learn much about programming, nor about MOO objects and verbs but you will get the ``feel'' for doing more difficult things later on. If you don't want to do something too simple, you can instead work directly on the next tutorial in section 8.4 on page gif.

Ok, let's assume that you sometimes hate something, e.g. your boss or your computer. Now let's program a simple objet that you can kick and that will help you to get rid of your frustrations.

STEP 1 - Creating an Object:

First of all, we have to tell the MOO to create an object on which you can work, to do this type now:

>@create $thing named computer
The MOO now will reply with something like:
You now have computer with object number #4134
and parent generic thing (#5).
Each object you create has a unique number (which will allow you to find it everywhere). To make really sure that you indeed now own an object called computer, type now:
  @audit me
You will get a listing of all objects you own (including yourself and rooms and exits you may have built). Also note that when you create an object with the @create command it will be ``on you'', i.e. in your inventory. If you don't believe this, type now: ``inv''.

STEP 2 - Adding a description

Now look at your object, i.e. type now:

   look computer
You will ``see nothing special'' of course. So the first thing you do is to add a description, type now:
   @describe computer as A really disgusting looking little PC.
Now look at it again! Note that you can enter a different description of course if your machine has nice looks. Just do the @describe command again.

STEP 3 - Let's add a command verb

Since you sometimes hate your computer you want to kick it sometimes, right ? Now kicking objects is not a standard command in a MOO unless it is on some social feature (see section 2.4). What we do now is add a ``kick'' verb just for this ``computer'' (more explanations later). For now just type this: (be very careful to type exactly this and nothing else)

@verb computer:kick this any any
The MOO now should reply something like:
Verb added  #4134:"kick"  this any any  rd  (1)
Note the object number #4134 will not be the same since your computer has a different number ! In case you did something wrong (like forgetting the ``this any any'', type ``@rmverb computer:kick''. This will kill what you did. Note that you can also kill the whole object with the command ``@recycle computer'', but then you have to restart with STEP 1.

Very important: Don't use this ``@verb'' command more than once !! Else you will wind up with several verbs.

STEP 4 - Let's program the command verb

Type the exact 3 following lines now to program the verb:

  @program #4134:kick
  player:tell("The ", this.name, " yells: AIEAIE");
  .
Don't forget the dot. Actually, when you type your verb you will see something like this:

  >@program #4134:kick
   Now programming #4134:"kick"  this any any  rd  (1)
   [Type lines of input; use `.' at the beginning of a NEW LINE
   to end your input or type `@abort' to abort the command.]
  >player:tell("The ", this.name, " yells: AIEAIE");
  >.
   0 errors.
   Verb programmed.
In case you encounter an error, just restart until it works. In most MOO clients you can recall the previous command, edit the line and send it back. You may encounter another problem: the MOO seems to be stuck. In this case you forgot to enter the ``.'' on a new line. Do it !

Here is a typical error you might have done, e.g. you forgot a ``*"'' as in the following example:

   >@program #4134:kick
   Now programming #4134:"kick"  this any any  rd  (1)
   [Type lines of input; use `.' at the beginning of a NEW LINE to end your input or type `@abort' to abort the command.]
   >player:tell("The , this.name, "yells: AIEAIE");
   >.
   Line 1:  parse error
   1 error(s).
   Verb not programmed.
The first and the third line are moo commands necessary to define a verb. The second line is the real program you wrote. Note that we use a builtin MOO function ``player:tell'' that will print out something to the person that uses a verb. This function must be called with a list of arguments that are printed back to the user. In our case we have 3 arguments:
  1. "The "
  2. this.name
  3. " yells: AIEAIE"
The first and the third are simple strings that are printed to the user. The second one is more complex: it refers to the name of the objects on which the verb is programmed, i.e. your computer. Using a variable instead of a string ``computer'' makes your verb more versatile as you will see in step 5.

Note that when you program more complex commands than this ``1 line'' procedure you will use an editor to do this. (We will explain this in the next tutorial in section 8.4.3 on page gif)

STEP 5 - Testing

To test your ``computer'', type now like in the following transcript:

   >kick computer
    The computer yells: AIEAIE
Hey it works ! Now, if you happen to hate your boss, just rename the object as in the following example:

   >@rename computer to boss
   Name of #4134 changed to "boss", with aliases {"boss"}.
   >kick boss
   The boss yells: AIEAIE

How come it works ? Well, go and do the next tutorial (section 8.4). It will teach you much more. However, it will take you about 4 to 8 hours to master it. Ok you don't want to learn much more, but just a little bit more, go to STEP 6 now.

STEP 6 - Counting the kicks

Ok so you really hate your boss and you think that other's hate him too. Now let's add a counter to count all the kicks. In this case you need a ``property'' on your ``boss'' object to count the kicks. A property is some kind of place where you can store information on an object.

Add it now with the following command (make sure you type it right):

@prop boss.kicks 0
The MOO will display something like this:
Property added with value 0.

Now you have to modify the verb of course. Enter the following lines as below or use a MOO editor if you allready know how to do this. If you don't you should actually learn it now e.g. by glancing at the relevant text in in section 8.4.3 on page gif): Before you start typing make sure that you enter ``player:tell("The ", this.name, " having been hit allready ", this.kicks, " times, yells: AIEAIE");'' on a single line !!

   @program #4134:kick
   player:tell("The ", this.name, " having been hit allready ",
this.kicks, " times, yells: AIEAIE");
   this.kicks = this.kicks + 1;
   .
The line ``this.kicks = this.kicks 1;'' will increase the kicks property on your object each time the verb is called. This construct is called a counter by the way. Also note that we had to modify the ``player:tell'' verb to display the kicks received so far. Now test your verb again! You should see something like:
  >kick boss
  The boss having been hit allready 6 times, yells: AIEAIE

STEP 7 - Making sure you can do it alone

Ok so actually you love your boss (sometimes). Well add a second verb called ``hug''. Just redo step 3 to step 6 with a different verb !


next up previous contents index external
Next: 8.4 MOO tutorialLevel Up: Basic MOO Programming Tutorial Previous: Procedural/structural Programming

Daniel K. Schneider
Thu Apr 17 12:43:52 MET DST 1997