Difference between revisions of "Manual:DIL Manual/cmdptr"

From DikuMUD Wiki
Jump to navigation Jump to search
(XML import)
(checked against the compiler and the interpreter; example compiles)
 
Line 1: Line 1:
−
<span id="cptr"></span>
+
= cmdptr =
−
'''Type:  '''<i><!--CODE-->cmdptr</i><!--ENDCODE-->
+
'''Type.''' A pointer to one of the game's commands.
−
'''cmdptr fields'''
 
  
−
 
−
'''name'''
 
−
            string - command name
 
−
'''type'''
 
−
            integer - command type like social or skill or just command
 
−
'''level'''
 
−
            integer - minimum level to use command
 
−
'''loglevel'''
 
−
            integer - level of character that can see the log 0 for no logs
 
−
'''position'''
 
−
            integer - minimum position to use command
 
−
'''next'''
 
−
            cmdptr - pointer to the next cmdptr
 
−
'''previous'''
 
−
            cmdptr - pointer to the previous cmdptr
 
−
 
−
 
−
  The cmdptr can be used to search the command list or display all the commands.
 
−
I0t is also now possible to sort the commands by type by defining your own command
 
−
types and using the type field to sort on.
 
−
 
−
  In order to get the first command in the list you use the following function:
 
−
'''Function:  '''<i><!--CODE-->chead();</i><!--ENDCODE-->
 
−
If you want to get a specific command then you use the following function:
 
−
'''Function:  '''<i><!--CODE-->cmdptr := getcommand (s : string );</i><!--ENDCODE-->
 
−
'''Example:'''
 
−
<i><!--CODE-->
 
−
---~---~---~---~---~---~---~---~---
 
−
 
−
dilbegin cmdtst(arg : string);
 
 
  var
 
  var
−
  cmd : cmdptr;
+
    cmd : cmdptr;
−
  st : string;
 
−
 
 
−
code
 
−
dilend
 
−
 
 
−
---~---~---~---~---~---~---~---~---
 
−
 
 
−
</i><!--ENDCODE-->
 
  
 +
A cmdptr gives a program the facts about a command, as set in <code>commands.def</code>: its name, type, and who may use it. <code>chead()</code> is the first command, <code>cmd.next</code> the next one (null after the last), and <code>getcmd(word)</code> the command a word means when typed, abbreviations included.
  
−
---~---~---~---~---~---~---~---~---
+
== Fields ==
−
<span id="cptr"></span>
+
{| class="wikitable"
−
'''Type:  '''<i><!--CODE-->cmdptr</i><!--ENDCODE-->
+
! Field !! Type !! Meaning
−
'''cmdptr fields'''
+
|-
 +
| [[Manual:DIL Manual/name|name]] || string || the command's full name
 +
|-
 +
| [[Manual:DIL Manual/type|type]] || integer || its type: <code>TYPE_SOCIAL</code>, <code>TYPE_SKILL</code> and the others in <code>values.h</code>
 +
|-
 +
| [[Manual:DIL Manual/level|level]] || integer || the lowest level that may use it
 +
|-
 +
| [[Manual:DIL Manual/position|position]] || integer || the lowest position it can be used in (<code>POSITION_...</code>)
 +
|-
 +
| [[Manual:DIL Manual/loglevel|loglevel]] || integer || from which level the use is logged; 0 for not at all
 +
|-
 +
| [[Manual:DIL Manual/speed|speed]] || integer || its speed in combat
 +
|-
 +
| [[Manual:DIL Manual/next|next]] || cmdptr || the next command
 +
|}
  
 +
Each field's page has the details.
  
−
'''name'''
+
== Notes ==
−
            string - command name
+
* Commands stay for as long as the server runs, so cmdptr variables keep their value through waits. They are not saved with a unit: after loading they are null.
−
'''type'''
+
* A field of a null cmdptr fails; test <code>cmd == null</code> first.
−
            integer - command type like social or skill or just command
+
* There is no <code>previous</code> field, and the function is <code>getcmd()</code>, not <code>getcommand()</code>, though older pages said so.
−
'''level'''
+
* <code>cmd.profession</code> compiles but stops the program with a type error when it runs.
−
            integer - minimum level to use command
 
−
'''loglevel'''
 
−
            integer - level of character that can see the log 0 for no logs
 
−
'''position'''
 
−
            integer - minimum position to use command
 
−
'''next'''
 
−
            cmdptr - pointer to the next cmdptr
 
−
'''previous'''
 
−
            cmdptr - pointer to the previous cmdptr
 
  
−
 
+
== Example ==
−
  The cmdptr can be used to search the command list or display all the commands.
+
<pre>
−
I0t is also now possible to sort the commands by type by defining your own command
+
dilbegin do_mycmds(arg : string);
−
types and using the type field to sort on.
+
var
−
 
 
−
  In order to get the first command in the list you use the following function:
 
−
'''Function:  '''<i><!--CODE-->chead();</i><!--ENDCODE-->
 
−
If you want to get a specific command then you use the following function:
 
−
'''Function:  '''<i><!--CODE-->cmdptr := getcommand (s : string );</i><!--ENDCODE-->
 
−
'''Example:'''
 
−
<i><!--CODE-->
 
−
---~---~---~---~---~---~---~---~---
 
−
 
 
−
dilbegin cmdtst(arg : string);
 
−
var
 
 
   cmd : cmdptr;
 
   cmd : cmdptr;
−
   st : string;
+
   s : string;
−
 
+
code
−
code
+
{
 +
  cmd := chead();
 +
  while (cmd != null)
 +
  {
 +
      if ((cmd.level <= self.level) and (cmd.type != TYPE_SOCIAL)
 +
          and (cmd.type != TYPE_SKILL))
 +
        s := s + cmd.name + " ";
 +
      cmd := cmd.next;
 +
  }
 +
  pagestring("You can use: " + s + "<br/>", self);
 +
  quit;
 +
}
 
dilend
 
dilend
 +
</pre>
 +
A command that lists the commands the player's level allows, leaving out socials and skills; adapted from <code>comm_dil</code> in commands.zon.
  
−
---~---~---~---~---~---~---~---~---
+
== See also ==
−
 
+
* [[Manual:DIL Manual/chead()|chead()]]
−
</i><!--ENDCODE-->
+
* [[Manual:DIL Manual/getcmd()|getcmd()]]
−
 
+
* [[Manual:DIL Manual/command()|command()]]
−
 
+
* [[Manual:DIL Manual/zoneptr|zoneptr]]
−
---~---~---~---~---~---~---~---~---
 

Latest revision as of 23:27, 14 November 2026

cmdptr

Type. A pointer to one of the game's commands.

var
   cmd : cmdptr;

A cmdptr gives a program the facts about a command, as set in commands.def: its name, type, and who may use it. chead() is the first command, cmd.next the next one (null after the last), and getcmd(word) the command a word means when typed, abbreviations included.

Fields

Field Type Meaning
name string the command's full name
type integer its type: TYPE_SOCIAL, TYPE_SKILL and the others in values.h
level integer the lowest level that may use it
position integer the lowest position it can be used in (POSITION_...)
loglevel integer from which level the use is logged; 0 for not at all
speed integer its speed in combat
next cmdptr the next command

Each field's page has the details.

Notes

  • Commands stay for as long as the server runs, so cmdptr variables keep their value through waits. They are not saved with a unit: after loading they are null.
  • A field of a null cmdptr fails; test cmd == null first.
  • There is no previous field, and the function is getcmd(), not getcommand(), though older pages said so.
  • cmd.profession compiles but stops the program with a type error when it runs.

Example

dilbegin do_mycmds(arg : string);
var
   cmd : cmdptr;
   s : string;
code
{
   cmd := chead();
   while (cmd != null)
   {
      if ((cmd.level <= self.level) and (cmd.type != TYPE_SOCIAL)
          and (cmd.type != TYPE_SKILL))
         s := s + cmd.name + " ";
      cmd := cmd.next;
   }
   pagestring("You can use: " + s + "<br/>", self);
   quit;
}
dilend

A command that lists the commands the player's level allows, leaving out socials and skills; adapted from comm_dil in commands.zon.

See also