|
This page contains code samples and explanations for some moo programs I've written. It also contains links to some tutorials you should check out. This page does assume that the reader has worked through and attempted to understand one of these tutorials, and so does not cover the exact same ground. Yib's Pet Rock is an excellent and recent (1999) tutorial. At this point, it is probably the best tutorial available, and if you want to learn MOO programming, you should work through it if you haven't already. The Wind-Up Duck tutorial, written back in the mists of time by yduJ of LambdaMOO was long been one of the few resources available to people learning how to program on the MOO. However, as alluded to in the followup MOO-Lore Pamphlet, there is at least one flaw: it encourages use of fork rather than suspend(). The `fork' statement creates a new task (a "forked task") while the currently-running task still goes on to completion, but a `suspend()' suspends the currently-running task (thus making it into a "suspended task"). Another tutorial that has helped many people is the Box of Donuts tutorial, available on BayMOO and elsewhere. This originated on MediaMOO and is discussed in a paper by Amy Bruckman. Loyd Blankenship's The Cow Ate My Brain is another one of the very early MOO Programming tutorials, though it's really more about building than programming. Canton Becker's "Unofficial" MOO Programming Tutorial is nice in that it gives assistance in using the editor, in addition to the other topics that it covers. Mark Horan's Drink Verb on a Can of Pepsi J.C. Ireland's Step by Step MOO Programming has a very organized presentation, and appears to be the beginning of a book which has not been completed. Daniel K. Schneider's Introduction to MOO Programming is a good source for starting to get in depth on the subject. DKS's page. MOO programming notes for ITC213/ETL413 is another really recent page (from 2000 believe it or not!). It makes me happy to think that it's not dead yet Jim. Some Code SnippetsBonkersBonkers automate expressing something spammy to a group of people chatting in the same room. As described in the Jargon File entry for bonk/oif,"In the MUD community, it has become traditional to express pique or censure by "bonking" the offending person. Convention holds that one should acknowledge a bonk by saying "oif!" and there is a myth to the effect that failing to do so upsets the cosmic bonk/oif balance, causing much trouble in the universe. Some MUDs have implemented special commands for bonking and oifing."The prototypical bonker has one player bonk the other player, then tells everyone there how the other player reacts. This type of bonker evolved into having a verb tell the room that another player farted, or did some other presumably humorous thing. While I personally didn't get my start writing bonkers, it is a very common way for people to begin programming. Typically, a bonker is programmed on a feature object. That way, any players who want to use the bonker can just @addfeature that feature object. Traditionally, the vast majority of feature objects on a MOO contain bonkers of various sorts. For illustration, I'll show a particularly boring and generic example of a bonker. There's some condition checking on it so that it gives different responses depending on who it's used on.
Here's what the people in the room see when the player uses the bonker on another player: JoeFeedback bonks Grump!@verb MyFO:"bonk" any any any rxd @program MyFO:bonk if (dobj == #-1 || dobj == #-2 || dobj == #-3) player:tell("Who do you want to bonk?"); elseif (!is_player(dobj)) player:tell("That isn't a player."); elseif (dobj.location != player.location) player:tell("You can't see ", dobj.name); elseif (dobj == player) player:tell("You bonk yourself!"); player:announce(player.name, " bonks ", player.pr, "!"); player:announce(player.name, " says \"Oif\""); else player:tell("You bonk ", dobj.name, "!"); player.location:announce_all_but({player, dobj}, player.name, " bonks ", dobj.name, "!"); player.location:announce_all_but({player, dobj}, dobj.name, " says \"Oif\""); dobj:tell(player.name, " bonks you!"); endif . Uttering something to a room, example - pottery
Saying Randomized stuffTarot DeckGaze (using MOO's DB)
Looping through Propertiessb2examroom
Movingtouradmire
Putting Stuff on the WebFor a good tutorial introducing you to HTML itself, see Elusive's HTML Tutorial at RiverMOO.At RiverMoo, you can simply edit your .html property and type in your web page as you like. This is the method expected by the above tutorial. However, this won't let you create the page on the fly substituting things into it. In order to do that, you will need to create a verb.
htext verb on a room at RiverMOOThis verb is going to return a list called lines containing the HTML for the page. In order to make it easier to follow, I am boldfacing "lines" each time it is redefined. The Title of the page is constructed from the name of the object. Throughout this code, note the use of embedded quote \" to get a quote mark (") to make it to the web page. You could also use " to get that quote mark. After the name of the room and an image (stored on another server), the contents of the html property or, if there is no html property, the room's description is returned. Before it is added to the lines list, the program checks to see if the property it is adding is a list, and if so, it runs the text_to_html verb from the $http object on it. That verb substitutes ", < and > for \", < and >. In the unordered list that follows the description there are two links: one to the Dilbert Zone, and one to another object on the MOO. Note that instead of #objectnumber, use /objectnumber. Next it loops through the collection of exits, outputting the destination room and object number in a clickable form. It does the same for the collection of virtual exits and objects which are contained in the room at the time the page is viewed.
@verb roomname:"htext" this none this rxd Items useful in an htext verb on a person at RiverMOOlines = {@lines, "Location: <A HREF=\"/" +tostr(tonum(this.location)) + "\">" + this.location.name + " (" + tostr(this.location) + ") </A><BR>"}; if (this in connected_players()) lines = {@lines, "Connected for " + $time_utils:english_time( connected_seconds(this)) + ".<BR>"}; lines = {@lines, "Idle for " + $time_utils:english_time(idle_seconds(this)) + ".<BR><HR>"}; else lines = {@lines, "Last disconnected on " + $time_utils:time_sub( "$n $T, $Y at $O:$M:$S $p $Z.<BR>", this.last_disconnect_time)}; lines = {@lines, "Disconnected for " + $time_utils:english_time(time() - this.last_disconnect_time) + ".<BR><HR>"}; endif
lines = {@lines, "<H2>Owned Objects:</H2>"}; Pronoun Substitution Reference |