Pour les instructions du tuteur sans les réactions de l'apprenant, cliquez ci-dessous:
>tune niels's tv to 11 niels tunes niels's tv to channel 11. >play 1 on niels's tv niels selects the tape <La lecon continue ainsi, le tuteur parle et l'eleve execute.> for viewing.. * * * * * * * * * * 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." >pause niels's tv niels pauses niels's tv momentarily. . . >resume niels's tv niels resumes viewing the tape. 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. " >autopause niels's tv niels sets niels's tv on 'auto-pause'. type 'res niels's tv' to resume playing after each pause... 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." >@create $thing named "distributeur de frites,frites" You now have distributeur de frites (aka frites) with object number #2891 and parent generic thing (#5). >inv Carrying: niels's radio plan niels's vcr distributeur de frites cdr says, "Lets make sure that nickname 'donuts' really works. Type 'drop donuts'." >drop frites You drop distributeur de frites. cdr says, "Now 'look donuts'. " >look frites You see nothing special. 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..." >@describe frites as "Une machine en acier inox qui ronronne et laisse echapper une odeur agreable de frites bien huileuses" Description set. 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"} >@property frites.kinds {"carree et jaune foncee avec de la mayonaise","hexagonale au ketchup","pommes alumettes a la sauce chinoise"} Property added with value {"carree et jaune foncee avec de la mayonaise", "hexagonale au ketchup", "pommes alumettes a la sauce chinoise"}. 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..." >@dump frites ;;#2891.("kinds") = {"carree et jaune foncee avec de la mayonaise", "hexagonale au ketchup", "pommes alumettes a la sauce chinoise"} ;;#2891.("key") = 0 ;;#2891.("aliases") = {"distributeur de frites", "frites"} ;;#2891.("description") = "Une machine en acier inox qui ronronne et laisse echapper une odeur agreable de frites bien huileuses" ;;#2891.("object_size") = {0, 0} "***finished*** 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." >@verb frites:eat this Verb added (0). cdr says, "To verify that you have created this verb, type '@verbs donuts' and you should see it listed.. ok?" >@verbs donuts I see no "donuts" here. >@verbs frites ;verbs(#2891) => {"eat"} 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."
niels selects the tape <
* * * * * * * * * *
>dumptape niels's tv
niels dumps the tape <
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:"
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:"
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 <<
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:"
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:"
cdr says, "Once you are in the editor you can see the available editor commands by typing 'look'. If you type 'help
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:"
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:"
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 <<
* * * * * * * * * *
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!"
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..."
@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! "
Bande numéro 2
niels dumps the tape <
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!"
@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."
@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."
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."
@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."
Patrick Jermann