Manual:DIL Manual/getfollower()

From DikuMUD Wiki
Jump to navigation Jump to search

getfollower()

Function (unitptr). Gets one of a character's followers by its place in the list.

getfollower(ch : unitptr, i : integer)

The followers are numbered from 0 to ch.followercount - 1, newest first: whoever started following last is number 0. Group members are followers with CHAR_GROUP set in their charflags; the group leader is the one they follow.

Parameters

Name Type Meaning
ch unitptr The character who is followed.
i integer The place in the list, from 0.

Returns

The follower at place i, or null when i is negative or not below ch.followercount.

Notes

  • When ch is null the function gives an error instead of null: u := getfollower(ch, 0) then writes "DIL SERIOUS: ... Type error in unit assignemt" to the zone log and the program stops. Test ch == null first.
  • When ch is not a character it fails, and an assignment of it leaves the variable as it was.
  • The other way round, a character's leader is its master.

Example

dilbegin string group_names(leader : unitptr);
var
   i : integer;
   u : unitptr;
   s : string;
code
{
   if (leader == null)
      return ("");
   s := leader.name;
   i := 0;
   while (i < leader.followercount)
   {
      u := getfollower(leader, i);
      if (isset(u.charflags, CHAR_GROUP))
         s := s + ", " + u.name;
      i := i + 1;
   }
   return (s);
}
dilend

Lists a group: the leader and the followers who are in the group, as the group commands in commands.zon do.

See also