* * * * * * * * * * MMTV Presents Coding with Cdr! A MOO Programming Tutorial for Absolute Beginners Part 1 * * * * * * * * * * cdr says, "Hi! I'm cdr. I'm here to help you learn to program in MOO! This tutorial is for Absolute Beginners, no previous programming experience in any language is assumed!" cdr says, "MOO, despite all the Bovine jokes you may have heard or made yourself, actually stands for 'Multi-user Object Oriented' programming language..." cdr says, "MOO is kind of a cross between C++ and LISP, but much easier to learn. When you learn to program in MOO you can build all kinds of fun things here on mediaMOO!" cdr says, "This is an INTERACTIVE tutorial! You will actually be coding a program while you watch the tape!" cdr says, "Here's how it works. I will suggest a line or two of code for you to write. I will then ask you to pause the tape and actually enter the code before resuming your viewing. " cdr says, "To pause or resume viewing this tape at any time type PAUSE TVNAME or RESUME TVNAME. Why not practice doing it now.. " cdr says, "Were you able to pause and resume without problems? Great! Let's get started." cdr says, "Oh, I just remembered. . Many people prefer to have the tv pause automatically after each line. If you would like to try this type 'autopause tvname'. Type resume to continue each time..." cdr says, "For our first programmed object let's make a Box of Donuts! It's real easy. Just type '@create $thing named Box of Donuts,donuts'. Pause the tape and make that box right now! I'll wait for you..." cdr says, "Did you do it? Type 'inv' to look at your inventory to make sure you've got it. You should see it listed there. " cdr says, "In the language of object oriented programming you just made a 'child' of the generic object $thing. The word 'donuts' is the alias or nickname for your object." cdr says, "Lets make sure that nickname 'donuts' really works. Type 'drop donuts'." cdr says, "Now 'look donuts'. " cdr says, " Hee, hee....Not a very appetizing description so far is it.." cdr says, "Lets change that boring description! Type @describe donuts as "You see a box of yummy scrumptious donuts begging to be eaten". Pause the tape and do it. I'll wait..." cdr says, "The next thing we'll do is create several kinds of donuts for inside the box. Type a line like the one that follows adding as many donut descriptions as you wish." @property donuts.kinds {"yummy cherry donut","tasty mooberry croissant", "creamy custard donut"} cdr says, "What we just did was add a property called 'kinds' to the object 'box of donuts'. This property is a list of 3 donut descriptions." cdr says, "Now let's see if you were successful. Type '@dump donuts' Do you see a property called 'kinds' with the correct donut descriptions? If you don't, try adding the property again..." cdr says, "Now that we have added the property, let's practice talking like real MOO programmers and describe what we did" cdr says, "Repeat after me: 'We added the PROPERTY 'kinds' to the OBJECT 'donuts' and INITIALIZED the property's VALUE to a LIST of CHARACTER STRINGS describing various donuts' Hey! Are we cool or what!" cdr says, "Now let's see if we can add an EAT verb to our donuts object so we can gobble up some of those donuts! Our EAT verb might be called like this 'eat donuts'. " cdr says, "To create the verb type '@verb donuts:eat this' Pause and do it now." cdr says, "To verify that you have created this verb, type '@verbs donuts' and you should see it listed.. ok?" cdr says, "Now lets make the verb DO something! When a player eats a donut let's have the player choose a donut kind at random and gobble it up." cdr says, "I will show you the complete program but don't type it in just yet... Here it is:" donut_choice = this.kinds[random(3)]; player.location:announce_all(player.name," gobbles up a ",donut_choice,"."); cdr says, "Let's talk about what's happening here before we try to enter the code..." cdr says, " In line 1 random(3) generates a random number from 1 to 3. ( If you had 5 donuts in your box you would make this random(5).) Let's suppose the function came up with the number 2.." cdr says, "The variable 'donut_choice would then be set to the second item in the list 'this.kinds', that is, the value of 'donut_choice' would now be "tasty mooberry croissant"" cdr says, "When a player eats a randomly selected donut everyone in the room should be informed of this event. This is the job of the second line." cdr says, "In line 2 'player.location' is the location of the player who is eating the donut, usually some room." cdr says, "The verb 'announce_all' is a verb defined for all rooms and it means 'tell everybody in the room' something or other.. " cdr says, "If Jill had typed 'eat donut' all players in the room (including Jill) would see 'Jill gobbles up a tasty mooberry croissant.'" cdr says, "Now lets program that verb! You will need to type in the three lines I will show you followed by a period on a line by itself." cdr says, "The first line actually creates a new verb named EAT and assigns it to the object 'donuts'. You will be prompted for the remaining two lines. Don't forget to end with a period on a separate line.." cdr says, "Pause the tape now and try entering the program:" @program donuts:eat donut_choice = this.kinds[random(3)]; player.location:announce_all(player.name," gobbles up a ",donut_choice,"."); cdr says, "If you were successful you will get my FAVORITE message '0 errors, verb programmed'. Congratulations! " cdr says, "If you were not so lucky you got some cryptic message about a parse error or whatnot. Just try again.." cdr says, " Did you remember the semicolons at the ends of the lines? Did you get the full colon in the right place? Pause the tape if you need to try again. I'll wait..." cdr says, "Now let's try out that verb. Type 'eat donuts' 3 or four times. Yum Yum! Congratulations! You are on your way to becoming a true blue MOO programmer!" cdr says, "Next time we will introduce some more fun features of the MOO language and we'll learn how to use the editor! Until then, HAPPY MOOING!" cdr says, "Bye bye!" >> END OF TAPE << * * * * * * * * * * MMTV Presents Coding with Cdr! A MOO Programming Tutorial for Absolute Beginners Part 2 * * * * * * * * * * cdr says, "Hi! I'm cdr. I'm here to help you learn to program in MOO! This tutorial is for Absolute Beginners, no previous programming experience in any language is assumed!" cdr says, "Last time we met we built a Box of Donuts. This time we will elaborate the code for this object and learn to use the MOO Editor. Let's look again at our original program:" @create $thing named Box of Donuts, donuts @property donuts.kinds {"tasty apple turnover", "yummy mooberry croissant", "shiny glazed donut"} @verb donuts:eat this @program donuts:eat donut_choice = this.kinds[random(3)]; player.location:announce_all(player.name," gobbles up a ",donut_choice,"."); . cdr says, "Before we continue please check your inventory (inv) to be sure you have already created a Box of Donuts. If you haven't please review the first tutorial tape where you will find directions for creating it." cdr says, "Remember, this is an INTERACTIVE tutorial! You will actually be coding a program while you watch the tape!" cdr says, "Recall that you can set your tv to 'autopause' for self pacing. (type 'autopause tvname'). Just type 'resume tvname' whenever you're ready for the next instruction." cdr says, "Today we will make our donut object more dynamic. We started out with 3 donuts, but in our original program we could eat and eat and never empty the box. Lets fix that rather uncharacteristic behavior." cdr says, "We will change the first line of the program to read:" donut_choice = this.kinds[ random(length(this.kinds)) ]; cdr says, "Note that we have replaced the number 3 with 'length(this.kinds)'. This is because the number of donuts in the box will vary. 'length(this.kinds)' gives the number left." cdr says, "In order to effect this change we will use the MOO Editor. We are going to invoke the editor, list our original program, make a text substitution, compile the new code, and exit the Editor. Whew!" cdr says, " I can't help you once you are 'in' the Editor so write down these commands:" @edit donuts:eat list s/3/length(this.kinds)/1 compile q (stands for 'quit editor') cdr says, "The second command means 'substitute length(this.kinds) for 3 in line #1'. And 'q' quits the editor." cdr says, "Once you are in the editor you can see the available editor commands by typing 'look'. If you type 'help ' you can get help on a specific command." cdr says, "Pause the tape and try it now: May the force be with you!" cdr says, "To see if you were successful, type '@list donuts:eat' Do you see the changes?" cdr says, "If you were unsuccessful just keep mucking with the editor until you get it to work. The editor is NOT easy to learn and mistakes are inevitable.. keep trying." cdr says, "It is worth while spending some time mucking around with the MOO Editor. It's a line editor and a bit quirky but if you program a lot you'll find yourself using it frequently. " cdr says, "Our next step is to build some logic into the program: IF (there are donuts left in the box) THEN (let the player take one and eat it) ELSE (tell the player they're all gone)." cdr says, "In MOO code the general form for such an IF/THEN/ELSE statement is: 'if (x is true) (do y) else (do z) endif'. Study the pattern in the following code:" if (this.kinds) donut_choice = this.kinds[random(length(this.kinds))]; player.location:announce_all(player.name," gobbles up a ",donut_choice,"."); else player.location:announce_all(player.name," reaches for a tasty donut, but the box is empty!"); endif cdr says, "In MOO code the expression (this.kinds) is considered to be TRUE if there are 1 or more items in the list, FALSE if the list is empty." cdr says, "Now we need to use the editor again to enter the new lines. When you renter the editor type 'list' and you will see the current program. We want to insert the line 'if (this.kinds)' at the very beginning." cdr says, "To do this we must set the 'insertion point' of the editor to be above line #1. You must type ins ^1 to do this. Then enter the correct line prefixed by a quotation mark \" , as if you were 'speaking' to the editor." cdr says, "Go ahead and try it now. Invoke the editor and try to add a new first line. List the program to see if it worked. Then quit the editor and lets plan the next step. Good Luck!" cdr says, "Once again, if you had troubles try again. The Editor can be exasperating at times until you get used to it." cdr says, "Now that you have a feel for the editor figure out where to insert the rest of the new lines. If you want to set the insertion point after a line, type 'ins _6'. Don't forget to 'compile' and q(uit)." cdr says, "If you have tried out the new verb you may have noticed that we can STILL eat all the donuts we want, the box never seems to get empty! Lets fix that now." cdr says, "We need to add the following line just after getting the donut_choice:" this.kinds = setremove(this.kinds, donut_choice); cdr says, "This new line removes the eaten donut from the list of donut kinds - that donut is no longer in the box and the length of 'donuts.kinds' decreases by 1." cdr says, "Finally, we need a way to refill the box of donuts when it gets empty. Lets make a verb BAKE DONUTS." cdr says, "I will give you the complete code: Use the skills you have learned to practice entering the program:" @verb donuts:bake this @program donuts:bake this.kinds = {"tasty apple turnover", "yummy mooberry croissant", "shiny glazed donut"}; player.location:announce_all(player.name, " bakes up a new batch of fresh donuts!"); . cdr says, "Pause the tape and try creating that new BAKE verb." cdr says, "If everything worked out ok, you should now have a refillable box of donuts. Try it out. Eat donuts until they're all gone. Then try baking up some more! Oooh don't get sick!" cdr says, "Remember to save one of those donuts for me! Next time we will introduce some more fun features of the MOO language. Until then, HAPPY MOOING!" >> END OF TAPE << Arkasha dumps the tape <>. * * * * * * * * * * MMTV Presents Coding with Cdr! A MOO Programming Tutorial for Absolute Beginners Part 3 * * * * * * * * * * cdr says, "Hi! I'm cdr. I'm here to help you learn to program in MOO! This continuing tutorial is for Absolute Beginners, no previous programming experience in any language is assumed!" cdr says, "Last time we met we finished making a Box of Donuts and learned to use the MOO editor." cdr says, "This time we will take on a slightly more ambitious project. We will build a Little Red Car to travel around mediaMOO in!" cdr says, "Maybe you've seen the MMTV helicopter or taken a ride in it. It's built on the same ideas that we will use to make our Little Red Car." cdr says, "Once you get the basic idea of how a car is made you can custom design your own preferred kind of vehicle." cdr says, "Remember, this is an INTERACTIVE tutorial! You will actually be coding a program while you watch the tape!" cdr says, "It would be a good idea at this point to set your tv set on autopause. Type 'autopause tvname'. Type 'resume tvname' for each new instruction." cdr says, "To create our new car we will take advantage of a very useful generic object called the 'Generic Portable Room', object number #445." cdr says, "If you type @parents #445 (Do it now!) you can see that the Generic Portable Room is just a fancier version or 'child' of other Generic Room types." cdr says, "What makes the Generic Portable Room so useful is that it can be moved wherever you want and when it moves everyone in the room moves with it!" cdr says, "We are going to adapt this special room to serve as a car! Type the following line to create a car as a child of the Generic Portable Room." @create #445 named Little Red Car, car cdr says, "Now describe the car something like this: @describe car as "You see a sporty little red car." " cdr says, "Lets see how the car works. Drop the car and look at it. Then 'enter car', 'look', and type 'out' to exit. Pause and try out these commands." cdr says, "Next we need to describe the inside of the car. Type @describe_inside car as "You see plastic covered seats and a stick shift." " cdr says, "Now enter your car again and confirm that the interior description is correct." cdr says, "Now the fun part! Let's make the car move! We will create a verb called 'drive'. Then to get to the E&L garden we just type 'drive #11' " cdr says, "It's possible to make the car drive to a named location but for starters lets keep things simple and require the driver to use the room number..." cdr says, "Create the verb as follows: @verb car:drive any" cdr says, "Now lets code the verb. Enter the following lines. (Don't forget to end the program with a single period on a line by itself.)" @program car:drive player.location:announce_all(player.name," starts up the car and heads for ",dobj.name,"."); suspend(3); this:moveto(dobj); cdr says, "Before you test your new verb lets talk about what we just did. The general form of all commands in MOO is 'Verb Direct_object Preposition Indirect_obj' " cdr says, "For example, in a command like 'give candy to john' the verb GIVE has a direct object CANDY and an indirect object JOHN separated by the preposition TO." cdr says, "In our verb Drive the room number typed in is in the Direct Object position and is referred to in the program by the word 'dobj'." cdr says, "Thus 'dobj.name' in the first line is the name of the room whose number was typed in." cdr says, "The second line is simple to understand. It means 'wait for 3 seconds'. The purpose of this line is to create the illusion of time spent in travel." cdr says, "Finally, the third line is the guts of the program. The car is moved to the specified location along with everything in it." cdr says, "In the command 'this:moveto(dobj);' the word 'this' refers to the car. 'This' always refers to the object that owns the verb." cdr says, "Well, enough of this theory! Let's take the car for a spin! But first, make sure you know the room number of this room right here so you can drive back. If you're not sure, type @location me cdr says, "Now enter your car and 'drive #994'. You should end up at the MMTV studio. Then drive back here. Have fun!" cdr says, "Wasn't that fun? Whee Ha! If you want to quit now you can. If not, stay tuned for how to code further enhancements.." cdr says, "Now some fine points. Right now other players can not see your car come and go. We need to create some messages for your car." cdr says, "To see what kind of messages you can muck around with type @messages car to see the default messages that are built in." cdr says, "The messages we are interested in are the three 'teleport' messages. Let's start with the message passengers see when the car arrives." cdr says, "Type this: @teleport car is "The car slows down and comes to a stop."" cdr says, "Next a message for what others see when your car drives off: @teleport_outside car is "The little red car drives off..."" cdr says, "Finally, a message for others to see when your car drives in @oteleport_outside car is "A little red car drives in..."" cdr says, "You may have noticed already that when you are in the car you can hear whats going on outside your vehicle. " cdr says, "You can turn the listen feature on or off by entering the car and typing @listen on or @listen off as you prefer." cdr says, "Well, if you want to you can quit now. If you are interested in even MORE enhancements stay tuned!" cdr says, "For the final touches to our little red car, let's have some random messages appear as the car is traveling between locations. Type the following:" cdr says, "@property car.events {"The radiator boils over..", "The radio begins playing your favorite oldie..","You stop for a traffic light.."}" cdr says, "We will use the same kind of programming method for presenting random events as we did in the previous donut tutorial. " cdr says, "Edit your 'drive' verb (remember how? Hint: @edit car:drive ) so the complete program looks as follows:" player.location:announce_all(player.name, " starts up the car and heads for ", dobj.name, "."); suspend(3); player.location:announce_all( this.events[random(3)]); suspend(3); this:moveto(dobj); cdr says, "This Little Red Car is getting to be Mega Cool! There are endless further enhancements we could make but we should probably quit here.." cdr says, "I'm looking forward to seeing what kind of vehicle you create after this tutorial session. Please drive by the studio sometime and show me!" cdr says, "Lots of luck! Take that Little Red Car for a spin. See ya around the moo!!" >> END OF TAPE <<