void add_command(string verb, object ob, string pattern)
Add command!!! My favourite command. How to use it. This is
what is used to drive all the 'read sign' things and so on. This
coupled with the tempory_items in rooms makes things very cute. Ok, how
to call add_command and a quick description of what it does.
Add_command is sort of like add_action in that it defines something you
can do. The difference with add_command is that you need to have an
object to reference. So you could not do the very 'say' using
add_command because there are no object references involved. However
you can do read, etc because you have to read semething. The object
passed is the object upon which the verb will be defined, which object
you wish to be called when the verb succeeds. In most cases this will
be this_object, but you can do cute things.... The pattern varible is
string something like the form "%D %p %I", or "%I %p %D". WHat does all
this gobbledy gook mean? Well, %D means direct object. This is the
object that is directly referenced, eg 'read book' book is the direct
object. In 'pour water into frog' water is the direct object and frog
the indirect object. The %p is a preposition, this is from
parse_command and in fact the things are passed almost directly to
parse_command so look at the docs on parse_commad for a more complete
explination of the other options. When a verb is matched and the object
matched it calls a function do_verb(object *in_dir, Params...) on the
object. ie do_read(). In cases where you only have a direct object
you do not need to check anything in the routine. If this fucntion
returns 0, the action is considered to have failed. If it returns 1 or
a string the action has suceeded. If it returns a string it uses this
for the name in the mulitple short. For example a flower with a note
attached as one object, you get the do_read proceedure to return "note";
Other notes:
If no pattern is give "%D" is assumed.
Example of usage.
inherit "/std/object";
void setup() {
set_name("rose");
set_short("nice red rose");
add_adjective( ({ "red", "nice" }) );
set_long("A lovely full stemed red rose. It is slim and slender "+
"reminding you of a beatiful a women.\nIt has a small note "+
"attached.\n");
}
void init() {
this_player()->add_command("read", this_object());
this_player()->add_command("present", this_object(), "%D to %I");
}
string do_read() {
write("The note says: To Khaos with love fro Pinkfish.\n");
return "note";
}
int do_present(object *obs) {
int i;
for (i=0;i < sizeof(obs) && !living(obs[i]);i++);
if (i == sizeof(obs))
return 0;
if (this_object()->move(obs[i]))
return 0;
this_player()->add_succeeded(obs[i]);
return 1;
}
See also:
add_action