|
|
|
|
So you've got your programmer bit, and you're ready to start coding? This module will show you which commands to use to create verbs and properties, and to set their attributes. What this module *doesn't* cover is the MOO programming language itself. For this, you'll need to refer to the LambdaMOO Programmer's Manual. There are also programming tutorials available from the net, the most famous of which is the Wind-Up Duck tutorial written by yduJ@LambdaMOO. There are a number of places where this tutorial can be found, the most noteworthy of this being under the MOO/MU* Document Library webpage. The URL is: http://lucien.sims.berkeley.edu/moo.html Before you begin programming verbs, you'll need to create an object of the appropriate type to put them on. If you haven't done so already, check out the help modules Creating Objects and Getting Information About Objects, both here in the Hippo Help Room. These modules will teach you how to: * create new objects, * list the verbs and properties of an object and its ancestors, and * get a listing of the MOO code of a particular verb. Once you have created your object, creating a verb on that object can be done using the @verb command. Syntax: @verb <object>:<verb-name(s)> @verb <object>:<verb-name(s)> <dobj> [<prep> [<iobj>]] For example, @verb here:@eject any none none creates a verb on the current room, named `@eject', which accepts an arbitrary direct object, no preposition, and no indirect object. Another example:
@verb #1000:cleanup creates a verb on object #1000 with the name `cleanup'. By default, this form of the command creates a verb that has no direct object or indirect object. What kinds of direct objects can be specified? none --- means that the verb does not take a direct object. this --- means that the verb takes only the object upon which it is defined as a direct object. any --- means that the verb takes a direct object, but not necessarily only the object upon which the verb is defined. The same specifications can be made for indirect objects. What kinds of prepositions can be specified? Here's a list: with/using at/to in front of in/inside/into on top of/on/onto/upon out of/from inside/from over through under/underneath/beneath behind beside for/about is as off/off of Note that some of the phrases on the previous page are not grammatical prepositions. But the system generously allows you to pretend that they are. There are two other ways of specifying a preposition: none --- means that the verb does not take a preposition. any --- means that the verb takes any of the prepositions listed on the previous page. Consider the verb `_recycle' created as a result of the following command: @verb #4:_recycle this none this Since this verb demands that it be given a direct object and an indirect object but no preposition, there is no way that this verb can be invoked from the command line! (The parser can never identify an indirect object without a preposition.) A useful trick, then, if you want your verb to be called only by other verbs and never from the command line, is to use `this none this' for the direct object / preposition / indirect object specification. It is possible to give more than one name to the same verb, by providing a list of names separated by spaces, and enclosed by quotation symbols ("). For example, if you wanted the same verb to handle both `dropping' and `throwing' of objects in the current room, then you can specify two names as follows: @verb here:"drop throw" any none none Another thing that you can do with verb names is to specify acceptable abbreviations. This is done using the asterisk (*) character. To invoke the verb, one would only need to supply those characters appearing before the asterisk, as a minimum. Example: if a verb is created using the command @verb here:th*row any none none then the verb `throw' can be invoked by typing any of the following: throw thro thr th Every object, verb, and property has bits of information associated with it, called permissions. Permission bits can be in one of two states, either set or unset. The state of a permission determines how the object, verb, or property may be accessed. The permissions associated with verbs are the following: read (r) -- If not set, only wizards and the verb owner can view the code. Otherwise, any player can view it. write (w) -- If not set, only wizards and the verb owner can change the code. Otherwise, any player can change it (dangerous!). execute (x) -- If set, the verb can be called from inside another verb. If not set, it can only be called from the command line. debug (d) -- If set, error messages are displayed and execution is halted whenever an error occurs. If not, execution just continues. While we're at it, here are the permissions associated with objects ... read (r) -- If not set, only wizards and the object owner can list its verbs and properties. Otherwise, any player can. write (w) -- If not set, only wizards and the object owner can add or delete the objects properties and verbs. Otherwise, any player can do so (dangerous!). fertile (f) -- If not set, only wizards and the object owner can create children of the object. Otherwise, anyone can. .. And here are the permissions associated with properties. read (r) -- If not set, only wizards and the object owner can get the value of the property. Otherwise, any player can. write (w) -- If not set, only wizards and the object owner can change the value of the property. Otherwise, any player can do so. change (c) -- If set, the ownership of the property changes in descendants of the object. If not, the ownership of the property in descendants does not change. For more information about permissions and their uses, you should refer to the LambdaMOO Programmer's Manual. For now, we will just look at ways in which these permissions can be set and unset. One way of setting verb permissions is at the time the verb is created. Syntax: @verb <object>:<verb-name(s)> <dobj> <prep> <iobj> <permissions> Here, <permissions> is a subset of `rwxd'. For example, the command @verb here:th*row any none none rx creates the verb `throw' on the current room with the read and execute permissions set. If a verb is created without specifying permission settings, the default setting `rd' is used. To change the permissions of a verb that has already been created, you can use the @chmod command. Syntax: @chmod <object>:<verb-name> <verb-permissions> Example: @chmod here:throw rd will change the permissions of verb `throw' on the current room, to `rd'. To clear all permissions, use "" as the second argument. For example, @chmod here:throw "" will unset all permissions on the verb `throw'. While we're at it, it's worth mentioning that the @chmod command can be used to change object and property permissions as well. Syntax: @chmod <object> <object-permissions> @chmod <object>.<prop-name> <property-permissions> Examples: @chmod here rf @chmod #720.notify_shouts r The @chmod command has a few other options which we won't cover here; for more information, type help @chmod When verbs are first created, they are empty of text. The associated object recognizes that the verb exists; however, running the verb doesn't accomplish very much! To add text to a verb, or indeed, to make any change you like, you need to edit it. Syntax: @edit <object>:<verb> For example: @edit here:@eject Editing verbs is very much like editing properties (such as your description) or MOO-mail messages, with one important difference: saving your work... When you save your work, the system attempts to compile your verb. If any syntax errors are discovered, error messages are produced, and the verb is not considered to be programmed yet. Your edit session can only be truly terminated if compilation is successful, or if the edit is aborted. For this reason, it's generally a good idea to do your verb editing external to the MOO, and to copy your text into the MOO whenever you want to try to compile it. On the next page, we'll see a command that makes it easy to load in verb code developed outside the MOO. In those situations where you want to enter the entire code for a verb, you may find the following command more convenient than @edit. Syntax: @program <object>:<verb-name> @program <object>:<verb-name> <dobj> <preposition> <iobj> Example: @program here:throw any none none asks the user to supply lines of code for the previously-created verb `throw' on the current room (that is, the copy of `throw' that takes any direct object but no indirect object). The user sees the following: [Type lines of input; use `.' to end or `@abort' to abort the command.] Once all the lines are entered, the program is compiled. If compilation is successful, then the code is installed as the new program for the verb. If compilation is not successful, the verb is left unchanged. So far, we have seen how to create new verbs for objects. Compared to verbs, creating properties is much more straightforward: Syntax: @property <object>.<prop-name> @property <object>.<prop-name> <initial-value> @property <object>.<prop-name> <initial-value> <permissions> Note that `@property' can be abbreviated to `@prop'. If the initial value is missing, the property is given a default value of 0. If the permissions are missing, a default setting of `rc' is assumed. Example: @property #720.notify_shouts creates the property `notify_shouts' on object #720 with value 0 and permissions r and c set. Example: @prop #6.gender "neuter" r creates the property `gender' on object #6 with value "neuter" and permission r set. There are several ways of changing the value of a property, but only two will be mentioned here. First, if the value of the property is a string or a list, it is possible to edit the property using the @edit command (as you may have done when setting your description). Second, you can use the @set command . Syntax: @set <object>.<prop-name> to <value> Example: @set me.description to "A rounded and rather hirsute man." What do you do if you decide you don't want your verb or property any more? To get rid of a property, use the @rmprop command. Syntax: @rmproperty <object>.<prop-name> Example: @rmprop me.notify_shouts To get rid of a verb, use the @rmverb command. Syntax: @rmverb <object>:<verb-name> @rmverb <object>:<verb-name> <dobj> <prep> <iobj> Examples: @rmverb here:throw @rmverb here:throw any to any The first form of the verb is the one you'll end up using most of the time. But it can happen that two verbs with the same name are defined on the same object. The second form allows you to distinguish between them by specifying the direct object / preposition / indirect object requirements of the particular copy you want to delete. In this module, we've seen some of the more important commands available to programmers. However, there are many more commands which can be useful --- too many to mention here. As a starting point for future investigation, you should consult the MOO system help on the following topics: prog-index programming And of course, be sure to read the LambdaMOO Programmer's Manual! |
|
This site is best viewed in 800 x 600, or 1024 x 768. If you find any faults in our page on certain browsers, please report them so we may fix the problem.Copyright © NJO
2001.
|