Manual:DIL Manual/pc head()
Jump to navigation
Jump to search
pc_head()
Function (unitptr). The first player in the game's global unit list.
pc_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.
pc_head() returns the first player, the one who entered the game last, or null when no players are on. Follow gnext while the unit is a player to visit everyone online.
Returns
Unitptr: the first player, or null if no player is in the game.
Notes
- Players are at the very start of the list, so when someone is on,
pc_head()is the same unit asghead(). The difference is thatpc_head()gives null instead of an NPC when nobody is on. - Stop at the first unit that isn't a player:
while (pc.type == UNIT_ST_PC). Whenpc_head()is null,pc.typefails and the loop doesn't run. - Don't wait inside the loop: unit variables are cleared at every wait unless
secured, so the walk would lose its place.
Example
dilbegin integer players_on();
var
pc : unitptr;
n : integer;
code
{
pc := pc_head();
while (pc.type == UNIT_ST_PC)
{
n := n + 1;
pc := pc.gnext;
}
return (n);
}
dilend
Counts the players in the game; competition.zon and wiz.zon walk the players the same way.