Manual:DIL Manual/room head()

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

room_head()

Function (unitptr). The first room in the game's global unit list.

room_head()

The global list holds every unit in the game, kept in this order: all players (the one who entered the game last first), then all NPCs, then all objects, then all rooms. Each unit's gnext is the next one in the list, and null after the last room.

room_head() returns the first room. Follow gnext to visit every room; after the last room gnext is null.

Returns

Unitptr: the first room, or null if there is none (never, in a running game).

Notes

  • Rooms are the end of the list, so while (u.type == UNIT_ST_ROOM) and while (u != null) end at the same place.
  • A program runs at most 52,000 instructions between two waits (WAITCMD_MAXINST in vme/src/dil.h); past that it is stopped with "had endless loop" in vme.log. The game holds many thousands of objects, NPCs and rooms, so a loop of a few instructions per unit over a whole section can run into that limit. You can't pause half-way either: unit variables are cleared at every wait unless secured.
  • To get one room, findroom("name@zone") is much cheaper than a walk.

Example

dilbegin integer rooms_in_zone(zn : string);
var
   u : unitptr;
   n : integer;
code
{
   u := room_head();
   while (u.type == UNIT_ST_ROOM)
   {
      if (u.zoneidx == zn)
         n := n + 1;
      u := u.gnext;
   }
   return (n);
}
dilend

Counts the rooms of zone zn.

See also