Manual:DIL Manual/gnext
Jump to navigation
Jump to search
Contents
gnext
Field (unitptr, read-only; units: all).
u.gnext : unitptr
The next unit in the game's global list of all units, or null after the last. The list is sorted by type: all players first, then all NPCs, then all objects, then all rooms. ghead() is its first unit; pc_head(), npc_head(), obj_head() and room_head() are the first of each type.
Notes
- It can't be assigned (vmc: "Illegal lvalue").
- The list holds tens of thousands of units. To visit one type, start at its head and stop at the first unit of another type; never walk the whole list.
- gprevious goes the other way. For the units in one place use next.
- A walk with a
waitorpausein it loses its unitptr variables at each wake. - On null it fails, and a field of a failed value is false in every comparison, so
while (u.type == UNIT_ST_PC)also ends at the end of the list.
Example
dilbegin unitptr find_player(pname : string);
var
pc : unitptr;
code
{
pc := ghead();
while ((pc.type == UNIT_ST_PC) and (pc.name != pname))
pc := pc.gnext;
if (pc.type != UNIT_ST_PC)
pc := null;
return (pc);
}
dilend
Finds a player in the game by exact name (case is ignored), looking only at the players.