First Verb

This will be an extremely simple object and verb, with the purpose of getting you familiar with adding and coding verbs.

Creating The Object

First, create a ball as a child of $thing. If you aren't sure how to do this, read the information here. Make sure one of its aliases is "ball" so that you can refer to it easily.

Defining A Verb

Before you can begin coding a verb, you must first define it. If you've programmed in C++, this is basically the same as declaring a function before you write the code for it.

There are basically two types of verbs in a MOO: command line and callable. We won't talk much about callable verbs for a while yet.

Command line verbs are simply verbs that can be typed as commands into the MOO. For instance, typing "drop ball" will execute a verb involved with dropping the ball. Each verb has three arguments. This simply means that every command line verb takes some form of:

verb argument1 argument2 argument3

In the case of the "drop" command, which is defined on $thing, argument1 is "this". "this" means simply whatever object the verb exists on. If you try to drop a ball, then any "this" in the argument list refers to the ball. argument2 and argument3 are both "none", which means nothing is typed there.

You've probably used a verb where all three arguments are "none". "Look", for instance, can be typed by itself with no arguments.

"@create" is a verb which needs all three arguments. argument1 is "any", which simply means anything can go there. argument2 is the preposition, which in this case is "called". And argument3 is "any" again.

This can be confusing, and it's not necessary to understand it all right now. Simply be aware that if you want to add a command to an object, the arguments you want will probably be "this none none".

And that brings us to the syntax for defining a new verb:

@verb <object>:<verb> <arg1> <arg2> <arg3>

For example:

@verb ball:kick this none none

Take note of the object:verb construction; it's used frequently. If you make a mistake adding a verb, don't just add it again, or there'll be two of them. Instead, use this command:

@rmverb <object>:<verb>

It will tell you the verb has been removed, and you can then try adding it again.

Programming A Verb

Go ahead and add the "kick" verb to your ball, if you haven't already. Your ball now defines a command line verb called "kick".

Trying typing "kick ball". Nothing happens, right? The MOO found your verb and executed it, but there was no code to execute, so nothing happened. So what we have to do now is add some code telling what to do when someone types "kick ball".

To begin programming a verb, the syntax is:

@program <object>:<verb>

For example:

@program ball:kick

The MOO will then be waiting to receive lines of text from you. No other commands will work until you finish coding the verb. To finish coding, you must simply type ".", a lone period.

The code for ball:kick is as follows:

player:tell("You kick ", this.name, " across the room.");
player.location:announce(player.name, " kicks ", this.name, " across the room.");

I suggest actually typing the code in, rather than copying and pasting, so that you begin to get used to the feel of the syntax. When you've entered the two lines, type a lone period to end programming.

If you're lucky, the MOO will tell you "0 errors. Verb programmed." This means that you were successful and the code was saved. Otherwise, you'll get an error, and it'll tell you which line to check first. In this case, you must simply repeat the @program command, then try entering the code again.

Important: Never take error messages at their word. Always keep in mind that this is a broken machine trying to tell you what's wrong with itself. This goes for any programming language. It will try to tell you the general area where the error occurred, but don't trust the line number to be exact. If you see nothing wrong with the line it tells you, check the line above. A missing semicolon, a very frequent mistake, will produce misleading errors like this.

Note: Only @rmverb can remove a verb. If your program had errors, the verb is still there, it just still doesn't have any code. Also, if you wish to overwrite a programmed verb with new code, simply use @program again and it will overwrite the old code. There's no need to remove the verb and add it again.

Some Other Things To Note

The syntax is probably fairly strange to you, but you can still tell a few things about the code:

Also note: