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).
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:
grumble ``now this is really too much'' to somebodyThe 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.
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))
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).
32: player.location:announce_all_but({addressee, player},
player.name, " grumbles", mess);
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.
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 !
messages={``a'', ``b'', ``c'',}
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).
>@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). */ --