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

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="extra"></span>
+
= extraptr =
−
'''The extraptr has the following fields:'''
+
'''Type.''' A pointer to an extra description.
  
−
     extraptr:
+
var
−
      'names'        :stringlist (RW)
+
     exd : extraptr;
−
          names is a list of strings of names, that the extra description matches on.
 
−
      'descr'        :string (RW)
 
−
          descr is the contents of the extra description.
 
−
      'next'        :extraptr (RO)
 
−
          next is the next extra description in a list.
 
−
      'vals'        :intlist (RW)
 
−
          vals is a list of integer values attached to this extra.
 
  
−
---~---~---~---~---~---~---~---~---
+
Extra descriptions are the texts a unit shows when looked at (<code>look at sign</code>), and DIL also uses them to store data on units: quest flags, counters, settings. <code>look</code> doesn't show an extra whose first name starts with <code>$</code>, so such names hold data. Each extra has these fields:
  
−
The unitptr is the key structure in the MUD, containing any kind of the
+
{| class="wikitable"
−
following subtypes:
+
! Field !! Type !! Meaning
 +
|-
 +
| [[Manual:DIL Manual/names|names]] || stringlist || the names it is found by
 +
|-
 +
| [[Manual:DIL Manual/name|name]] || string || the first of the names
 +
|-
 +
| [[Manual:DIL Manual/descr|descr]] || string || its text (read and write)
 +
|-
 +
| [[Manual:DIL Manual/vals|vals]] || intlist || numbers stored with it
 +
|-
 +
| [[Manual:DIL Manual/next|next]] || extraptr || the next extra on the same unit
 +
|}
  
−
    object      : a normal object, a sword, a vail, etc.
+
<code>u.extra</code> is the first extra of a unit. To find one by name, use <code>"name" in u.extra</code> or <code>u.extra.["name"]</code>; both give null when there is none.
−
    room        : a room, location or the like.
 
−
    pc          : a playing character.
 
−
    npc        : a non playing character (mobile, monster, etc)
 
  
−
---~---~---~---~---~---~---~---~---
+
== Notes ==
−
<span id="eptr"></span>
+
* '''An extraptr variable is cleared at every wait''' (<code>wait</code>, <code>pause</code>, a heartbeat), and it can't be secured. Look the extra up again after waiting.
−
'''Extraptr:'''
+
* A field of a null extraptr fails; test <code>exd == null</code> first.
 +
* <code>addextra()</code> and <code>subextra()</code> add and remove extras. An extra made with empty text is not added.
 +
* Extras themselves are saved with the unit; extraptr variables are not (they come back null).
  
−
   Extra descriptions, quests structures, etc can be searched and manipulated
+
== Example ==
−
using variables of this type. There is no way to declare static structures of
+
<pre>
−
this type in DIL programs. Lists of extra descriptions are easily searched with
+
dilbegin visit_count();
−
the 'in' operator (See below). Extraptr variables are 'volatile', and thus
+
var
−
cleared whenever there is a possibility that they are rendered unusable.
+
  pc : unitptr;
−
<span id="extra"></span>
+
   exd : extraptr;
−
'''The extraptr has the following fields:'''
+
code
 +
{
 +
  :start:
 +
  wait(SFB_DONE, command(CMD_AUTO_ENTER) and (activator.type == UNIT_ST_PC)
 +
        and (activator.outside == self));
 +
  pc := activator;
 +
  exd := "$visits" in pc.extra;
 +
  if (exd == null)
 +
  {
 +
      addextra(pc.extra, {"$visits"}, "1");
 +
      sendtext("Welcome, stranger.<br/>", pc);
 +
  }
 +
  else
 +
  {
 +
      exd.descr := itoa(atoi(exd.descr) + 1);
 +
      sendtext("Welcome back, visit number " + exd.descr + ".<br/>", pc);
 +
  }
 +
  goto start;
 +
}
 +
dilend
 +
</pre>
 +
On a room: counts each player's visits in a hidden extra on the player.
  
−
    extraptr:
+
== See also ==
−
      'names'        :stringlist (RW)
+
* [[Manual:DIL Manual/extra|extra]]
−
          names is a list of strings of names, that the extra description matches on.
+
* [[Manual:DIL Manual/addextra()|addextra()]]
−
      'descr'        :string (RW)
+
* [[Manual:DIL Manual/subextra()|subextra()]]
−
          descr is the contents of the extra description.
+
* [[Manual:DIL Manual/in|in]]
−
      'next'        :extraptr (RO)
+
* [[Manual:DIL Manual/descr|descr]]
−
          next is the next extra description in a list.
+
* [[Manual:DIL Manual/vals|vals]]
−
      'vals'        :intlist (RW)
 
−
          vals is a list of integer values attached to this extra.
 
−
 
 
−
---~---~---~---~---~---~---~---~---
 
−
 
 
−
The unitptr is the key structure in the MUD, containing any kind of the
 
−
following subtypes:
 
−
 
 
−
    object      : a normal object, a sword, a vail, etc.
 
−
    room        : a room, location or the like.
 
−
    pc          : a playing character.
 
−
    npc        : a non playing character (mobile, monster, etc)
 
−
 
 
−
---~---~---~---~---~---~---~---~---
 

Latest revision as of 23:27, 14 November 2026

extraptr

Type. A pointer to an extra description.

var
   exd : extraptr;

Extra descriptions are the texts a unit shows when looked at (look at sign), and DIL also uses them to store data on units: quest flags, counters, settings. look doesn't show an extra whose first name starts with $, so such names hold data. Each extra has these fields:

Field Type Meaning
names stringlist the names it is found by
name string the first of the names
descr string its text (read and write)
vals intlist numbers stored with it
next extraptr the next extra on the same unit

u.extra is the first extra of a unit. To find one by name, use "name" in u.extra or u.extra.["name"]; both give null when there is none.

Notes

  • An extraptr variable is cleared at every wait (wait, pause, a heartbeat), and it can't be secured. Look the extra up again after waiting.
  • A field of a null extraptr fails; test exd == null first.
  • addextra() and subextra() add and remove extras. An extra made with empty text is not added.
  • Extras themselves are saved with the unit; extraptr variables are not (they come back null).

Example

dilbegin visit_count();
var
   pc : unitptr;
   exd : extraptr;
code
{
   :start:
   wait(SFB_DONE, command(CMD_AUTO_ENTER) and (activator.type == UNIT_ST_PC)
        and (activator.outside == self));
   pc := activator;
   exd := "$visits" in pc.extra;
   if (exd == null)
   {
      addextra(pc.extra, {"$visits"}, "1");
      sendtext("Welcome, stranger.<br/>", pc);
   }
   else
   {
      exd.descr := itoa(atoi(exd.descr) + 1);
      sendtext("Welcome back, visit number " + exd.descr + ".<br/>", pc);
   }
   goto start;
}
dilend

On a room: counts each player's visits in a hidden extra on the player.

See also