add_command_examples |
Discworld creator help |
add_command_examples |
Examples
The general way to call add_command() on this_player() in an init() function, that will cause it to define the command for all living objects in the vicinity of the object that had the init() function.
void init() {
if ( !this_player() )
return;
this_player()->add_command( "wave", this_object() );
...
} /* init() */
This lets the user type things like 'wave wand'. It will match a wand in the players inventory, or in the environment.
Using simple object matching
add_command("load", ob,
"<direct:object:here> with <indirect:object:me>");
Which will, when parsed 'load camel with flour', will match the camel in the environment and the flour in their inventory.
Using direct objects in another object
add_command("unload", ob,
"<indirect:object:direct-obs> [from] <direct:object:here>");
This will allow the player to unload things out of the camel. The indirect objects will be matched inside the camel (which is the direct object). Eg: 'unload flour from camel'.
Words placed in the string must be matched. However, putting them in square brackets makes them optional. You can also do {from|out of} which will require one of 'from' or 'out of' in the match.
Using string, word and number
add_command("bow", ob,
"<string'adjective'> [to] <indirect:any-living>");
This is an example of a soul command pattern. Soul commands allow you to use multi-word optional parameters, (Eg: 'think like a rabbit'), so it is specified as a string. The word 'to' is optional. You can have it, or not have it. Eg: 'bow colourfully to pinkfish' and 'bow colourfully pinkfish' both have the same effect.
The 'adjective' will cause the syntax of the command to read: bow <adjective> [to] <any-living>
As well as string you can use word to match a single word or number to match a number.
Using fractions
add_command("pour", ob,
"<fraction> of <direct:object> into <indirect:object>");
This sets up a pour command for a container, it allows you to pour a fraction of it into some other container Matches things like 'pour 1/2 of bucket into cauldron'.
add_action equivalent
add_command("smell", ob, "<string'anything'>");
This will call your do_smell function with the pattern variable containing the matched string.