Manual:DIL Manual/gprevious

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

gprevious

Field (unitptr, read-only; units: all).

u.gprevious : unitptr

The unit before u in the game's global list of all units, or null for the first. The list is sorted by type: all players first, then all NPCs, then all objects, then all rooms. gnext goes the other way.

Notes

  • It can't be assigned (vmc: "Illegal lvalue").
  • Useful to get from any player to the first one: walk back while the previous unit is a player.
  • On null it fails; a field of a failed value is false in every comparison, so while (u.gprevious.type == UNIT_ST_PC) stops at the start of the list.

Example

dilbegin tell_all(pc : unitptr, msg : string);
var
   u : unitptr;
code
{
   u := pc;
   while (u.gprevious.type == UNIT_ST_PC)
      u := u.gprevious;
   while (u.type == UNIT_ST_PC)
   {
      sendtext(msg + "<br/>", u);
      u := u.gnext;
   }
   return;
}
dilend

Sends a text to every player in the game, starting from any one of them, as the broadcast command in basis.zon does.

See also