Difference between revisions of "Manual:DIL Manual/cmdptr"
Jump to navigation
Jump to search
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| Line 1: | Line 1: | ||
| − | + | = cmdptr = | |
| − | + | '''Type.''' A pointer to one of the game's commands. | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
var | var | ||
| − | + | cmd : cmdptr; | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| + | 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 == | |
| − | < | + | {| class="wikitable" |
| − | + | ! Field !! Type !! Meaning | |
| − | + | |- | |
| + | | [[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. | ||
| − | + | == 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 <code>cmd == null</code> first. | |
| − | + | * There is no <code>previous</code> field, and the function is <code>getcmd()</code>, not <code>getcommand()</code>, though older pages said so. | |
| − | + | * <code>cmd.profession</code> compiles but stops the program with a type error when it runs. | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | == Example == | |
| − | + | <pre> | |
| − | + | dilbegin do_mycmds(arg : string); | |
| − | + | var | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
cmd : cmdptr; | 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 | 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()]] | |
| − | + | * [[Manual:DIL Manual/getcmd()|getcmd()]] | |
| − | + | * [[Manual:DIL Manual/command()|command()]] | |
| − | + | * [[Manual:DIL Manual/zoneptr|zoneptr]] | |
| − | |||
Latest revision as of 23:27, 14 November 2026
Contents
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 == nullfirst. - There is no
previousfield, and the function isgetcmd(), notgetcommand(), though older pages said so. cmd.professioncompiles 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.