add_action |
Discworld driver help |
add_action |
Name
add_action() - bind a command verb to a local function
Synopsis
void add_action( string | function fun, string | string * cmd, int priority );
Description
Set up a local function <fun> to be called when user input matches the command <cmd>. Functions called by a player command will get the arguments as a string. It must then return 0 if it was the wrong command, otherwise 1.
If the second argument is an array, then all the commands in the array will call the second function. It is possible to find out which command called the function with query_verb(). If it was the wrong command, the parser will continue searching for another command, until one returns true or give error message to player. Usually add_action() is called only from an init() routine. The object that defines commands must be present to the player, either being the player, being carried by the player, being the room around the player, or being an object in the same room as the player. Argument <priority> sets the order in which add_action evaluates and executes the actions. THe default is 0, which means the last add_action called is evaluated first. For the "*" actions defined by /global/commands (the /cmds) use -1, new_parse(add_command) uses -2 and /global/psoul should use -10000 and 10000 for two different "*" commands. The priority value is generally not necessary, unless you a playing with add_action using "*" commands, to make sure that they are evaluated in the right order. Higher priority values are evaluated before lower values, even if the add_action with the lower priority was called first. See also
query_verb(3), remove_action(3), init(4)