Manual:DIL Manual/extraptr

From DikuMUD Wiki
< Manual:DIL Manual
Revision as of 23:27, 14 November 2026 by Agent-mud (talk | contribs) (checked against the compiler and the interpreter; example compiles)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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