external next up previous contents index
Next: 8.6 [TECFAMOO] ``E_WEB'' Tutorial Up: Basic MOO Programming Tutorial Previous: La morale de l'histoire

8.5 Social verb tutorial, level 0

 

This section will teach you how to write simple ``social'' verbs, i.e. verbs that just send messages around and do not modify the contents of any object. Ususally that kind of verb is made available in social features, but before writing and propagating those, it is better to write a few just for your own character.< In order to do the the Generic Objects and Permission Tutorial (see section 8.10) you don't need this section. So not much ``tutoring'' is done here and we rely on you for picking up the challenge! Feel free to pick it up later (i.e. once you know how to make generic objects and feature objects).

The "grumble" verb

Get the code from here if you want to play around with this verb. Then write your own social verb !

This verb shows a few more MOO programming tricks, all related to sending messages to users:

  1. This time we use a ``any to any'' verb specification. The reason is the following one. We want to say something like:
       grumble ``now this is really too much'' to somebody
    The first ``any'' specifier means that we can type in anything (e.g. a string) and the second ``any'' specifier means that we do not operate this verb on a specific object; ``any'' in this means a random user name.
  2. When you type a command like 'grumble Daniel' the MOO will try to find the object associated with the string ``Daniel''. This only works if the named object (``Daniel'' here) is in the same room. If found, it will set the variable iobj to the #object. But if no object was found, iobj will be not valid and we have to work out what to do with iobstr (see below).
        8:  if (!valid(iobj))
  3. Since the MOO parser does not find the addressee for us over distance (players in other rooms) we have to use a Lambda core utility function:
        9:    addressee = $string_utils:match_player(iobjstr);
    The ``iobj'' builtin variable will match IF the person or an object is in the same room, if not we set this variable to the player object we found (if any is found).
  4. Contrary to the ``holder'' tutorial (see section 8.4) we give differentiated feedback to the player who types the command, to players in the same room and so forth, e.g.

       32:    player.location:announce_all_but({addressee, player}, 
              player.name, " grumbles", mess);
  5. In order to page a person in a other room, we use the following verb:
       18:    addressee:receive_page("You hear " + player.name +
              " grumbling at you over distance: ", "    \"" + dobjstr + "!\"");

Here is the code. Please note that some lines have been broken for display here.

@verb me:grumble any to any

----------------------------------------------------------------------
>@l ~mooboy:grumble
@program ~MooBoy:grumble   any at any
 1:  "The grumble verb allows you to grumble at persons + objects
     in the same room";
 2:  "as well as to persons in other rooms. Players in the same room will see";
 3:  "your message, players in the distant room will just notice a grumbling";
 4:  "The only thing that sucks is that this is a any to any verb";
 5:  "Try 'grumble this is a test to xxx' to see what I mean";
 6:  "";
 7:  " --- test if the object or person is NOT in the same room";
 8:  if (!valid(iobj))
 9:    addressee = $string_utils:match_player(iobjstr);
10:    " ------ if not, is it a player ?";
11:    if ($command_utils:player_match_failed(addressee, iobjstr))
12:      player:tell("This player does not exist nor is there 
         any object of that name in this room");
13:    else
14:      " ------ it is a player and we can try to page it";
15:      if (addressee:is_listening())
16:        player:tell("You grumble-page to ", addressee.name, 
           " [", addressee.location.name, "]: \"", dobjstr, "\"");
17:        addressee:receive_page("You hear " + player.name +
           " grumbling at you over distance: ", "    \"" + dobjstr + "!\"");
18:        addressee.location:announce_all_but({addressee}, 
           "You vaguely hear that ", player.name, " grumbles something at ",
            addressee.name);
19:      else
20:        player:tell($string_utils:pronoun_sub("No need to grumble, 
            %s is not connected right now", addressee));
21:      endif
22:    endif
23:  else
24:    "------ the thing is in the same room, grumbling face to face";
25:    addressee = iobj;
26:    mess = " \"" + dobjstr + "\" " + prepstr + " " + addressee.name;
27:    if (is_player(addressee))
28:      player:tell("You grumble", mess);
29:    else
30:      player:tell("The ", addressee.name,
         " is not overly impressed by your grumbling.");
31:    endif
32:    player.location:announce_all_but({addressee, player},
       player.name, " grumbles", mess);
33:    addressee:tell(player.name, " grumbles at you, ", "\"", dobjstr, "!\"");
34:    addressee:tell(" ... maybe you should really start worrying...");
35:  endif
36:  /* Last edited on Tuesday, June 25, 1996 at 11:40.38 am by MooBoy (#1324). */
----------------------------------------------------------------------

Of course, this verb is not perfect yet. One thing missing might be permissions. right now this verb can be used by an other person that is in the same rooms as shown in the following examples:

An other person (e.g. Daniel) that is in the same room as Mooboy could type:

 >grumble "something" to MooBoy
 You grumble "something" to MooBoy

and MooBoy would see:

 Daniel grumbles at you, "something!"
 ... maybe you should really start worrying...
This works because the MOO parser will find the ``grumble'' verb on MOOBoy who is in the same room. Grumbling over distance would not work as shown in the following example. The reason is that no matching verb has been found either on the player typing the command, nor the room, nor any object that has been matched to the command typed.
>grumble "watch out" to Thora
I don't understand that.
We will address this and other security problems in an other tutorial [DOIT!], but you can look at sections 11.2 (general) or 12.4 (for specific information concerning TECFAMOO.)

Another problem that could be easily solved is that you can grumble at persons in the same room that are disconnected. No harm done, but one could filter that situation too.

The "grab" verb

Now let's look at a similar social verb, it is a simpler form of the previous verb, but has a permission check and some randomness built-in:

Get the code from here if you want to play around with this verb. Then write your own social verb !

  1. In line 11 we set the variable messages to a list of messages, something like messages={``a'', ``b'', ``c'',}
  2. In line 12 we select a random element of this list that will we displayed. message = messages[random(length(messages))]; uses the builtin random function to select an element of the list. Note that random(length(<list>) simply means select a random number between 1 and the length of the list (messages in our case).
  3. In the beginning of the verb (lines 6-9) we check if the caller of the verb is the same object as the object to which the verb belongs (you in this case). If this is not the case we print out a message to the caller, i.e. the person who typed the command.
>@l me:grab
@program ~MooBoy:grab   any none none
 1:  "The grab verb allows you to ``grab'' persons + objects in the same room";
 2:  "as well as persons in other rooms";
 3:  "All it really does is just displaying a random message to the other person";
 4:  "";
 5:  " ---- permission: only yourself can execute this verb";
 6:  if (caller != this)
 7:    player:tell("Sorry, you don't have permission to use this verb");
 8:    return;
 9:  endif
10:  " ---- list of messages and random generation of one --- ";
11:  messages = {".... maybe you really should start worrying a bit !",
 "You feel that this might be the start of something really dangerous",
 "You sense his virtual eyes on you!",
 ".... maybe you should disconnect",
 "Did you say good bye to your friends ?,
 you might just want to do that before it's too late!"};
12:  message = messages[random(length(messages))];
13:  " --- test if the object or person is in the same room";
14:  if (dobj == #-3)
15:    addressee = $string_utils:match_player(dobjstr);
16:    " ------ if not, is it a player ?";
17:    if ($command_utils:player_match_failed(addressee, dobjstr))
18:      player:tell("This player does not exist nor is there
         any object of that name in this room");
19:    else
20:      " ------ it is a player and we can try to page it";
21:      if (addressee:is_listening())
22:        player:tell("You grab ", addressee.name,
            "[at ", addressee.location.name, "] ", "over distance and ",
            addressee.ps, " sees: \"", message, "\".");
23:        addressee:receive_page("You feel " + player.name
           + " grabbing you over distance!", message);
24:      else
25:        player:tell($string_utils:pronoun_sub("No need to grab,
           %s is not connected right now", addressee));
26:      endif
27:    endif
28:  else
29:    "------ the thing is in the same room, grumbling face to face";
30:      addressee = dobj;
31:    if (is_player(dobj))
32:      player:tell("You grab ", dobjstr, " and ", addressee.ps,
         " sees: \"", message, "\".");
33:    else
34:      player:tell("The ", addressee.name,
         " is not overly impressed by your grabbing.");
35:    endif
36:    addressee:tell(player.name, " grabs you, ", dobjstr, "!", message);
37:  endif
38:  /* Last edited on Tuesday, June 25, 1996 at 2:04.43 pm by MooBoy (#1324). */
--


next up previous contents index external
Next: 8.6 [TECFAMOO] ``E_WEB'' Tutorial Up: Basic MOO Programming Tutorial Previous: La morale de l'histoire

Daniel K. Schneider
Thu Apr 17 12:43:52 MET DST 1997