API RegisterUserCommand

From Vendetta Lua
Revision as of 22:03, 25 January 2009 by Chefkoch (Talk | contribs) (split)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

RegisterUserCommand

Definition: RegisterUserCommand(string commandname, func callback(dataarg, {arguments1, ..}), data) -> nil
Description:
hook up object to command
Arguments:
commandname string containing the command
callback function accepting two arguments to run when command is executed
dataarg see data
arguments1 arguments of the command (Note: if there are no arguments the table is nil not an empty table.)
data data to pass callback
Example:

-- function to call when the command is entered
local function printfunc(data, args)
  -- data contains the third parameter of RegisterUserCommand
  local str = tostring(data)
  -- if the command was entered without parameters args is nil otherwise a table containing the parameters
  if args then
    str = str..tostring(args[1])
  end
  print(str)
end
RegisterUserCommand("printsomething", printfunc, "test")

Registers the command "printsomething" that calls a function that prints the text "test" and the first argument appended