Manual:DIL Manual/getcmd()

From DikuMUD Wiki
Jump to navigation Jump to search

getcmd()

Function (cmdptr). Finds a command from its name or an abbreviation.

getcmd(s : string)

Returns the command a player would get by typing s: getcmd("look") is the look command, getcmd("n") is north. Its fields (name, level, type, ...) are on the cmdptr page.

Parameters

Name Type Meaning
s string The command, whole or abbreviated, in lower case.

Returns

cmdptr: the command, or null when no command begins with s. It fails when s is a string variable that was never set.

Notes

  • An abbreviation gives the command the game picks for it, the same as when a player types it.
  • Case matters: commands are in lower case, so getcmd("Look") is null. Use
 tolower() on what a player typed.
  • getcmd("") is not null: it returns the first command in the list. Test for an
 empty string first.
  • Socials are in the list too (their type is TYPE_SOCIAL).

Example

dilbegin cmd_info(arg : string);
var
   cmd : cmdptr;
code
{
   if (arg == "")
   {
      sendtext("Which command?<br/>", self);
      quit;
   }

   cmd := getcmd(tolower(arg));
   if (cmd == null)
      sendtext("No command starts with '" + arg + "'.<br/>", self);
   else
      sendtext("'" + arg + "' is the command " + cmd.name + ", level " +
               itoa(cmd.level) + ".<br/>", self);
   quit;
}
dilend

A player command that tells which command a word stands for and its level.

See also