Manual:DIL Manual/next

From DikuMUD Wiki
< Manual:DIL Manual
Revision as of 23:00, 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

next

Field (same type as the value it is taken from, read-only; on unitptr, extraptr, zoneptr and cmdptr).

u.next : unitptr
e.next : extraptr
z.next : zoneptr
c.next : cmdptr

The next element of the list the value is in, or null after the last one:

  • unitptr: the next unit in the same place (the next one in u.outside.inside). Start with .inside of a room or container.
  • extraptr: the next extra description. Start with .extra or .info.
  • zoneptr: the next zone, in alphabetical order of zone names. Start with zhead().
  • cmdptr: the next command. Start with chead().

Notes

  • On null it fails, except on an extraptr, where it gives null.
  • It can't be assigned (vmc: "Illegal lvalue").
  • For the global list of all units use gnext instead.
  • A while loop that moves or kills units while it walks .next goes wrong: after link(u, elsewhere), u.next is in the other place. Use foreach() for that.
  • A loop with wait or pause in it loses its unitptr and extraptr variables at every wake.

Example

dilbegin count_items();
var
   u : unitptr;
   n : integer;
code
{
   u := self.outside.inside;
   while (u)
   {
      if (u.type == UNIT_ST_OBJ)
         n := n + 1;
      u := u.next;
   }
   act("There are " + itoa(n) + " things lying here.", A_ALWAYS, self, null, null, TO_CHAR);
   quit;
}
dilend

Counts the objects in the room.

See also