Manual:DIL Manual/chead()

From DikuMUD Wiki
Jump to navigation Jump to search

chead()

Function (cmdptr). The first command in the game's command table.

chead()

Returns the first entry of the command table, the commands loaded at boot from vme/etc/commands.dat (built from commands.def), in the order of that file. Each command's next field is the one after it, and null after the last, so a loop from chead() visits every command, socials and skills included. Fields such as name, type and level can then be read.

Returns

Cmdptr: the first command.

Notes

  • command_head() is another name for the same function.
  • cmd.type tells ordinary commands from socials and skills (TYPE_SOCIAL, TYPE_SKILL in vme/include/values.h); cmd.level is the level needed to use it.
  • cmd.next on a null cmdptr fails; test the pointer in the loop: while (cmd).

Example

dilbegin list_cmds(pc : unitptr);
var
   cmd : cmdptr;
   sl : stringlist;
code
{
   cmd := chead();
   while (cmd)
   {
      if ((cmd.level <= pc.level) and (cmd.type != TYPE_SOCIAL) and (cmd.type != TYPE_SKILL))
         addstring(sl, cmd.name);
      cmd := cmd.next;
   }
   sendtext(itoa(length(sl)) + " commands.<br/>", pc);
   return;
}
dilend

Collects the commands a character may use, leaving out socials and skills, as the commands command in commands.zon does.

See also