Manual:DIL Manual/idx

From DikuMUD Wiki
Jump to navigation Jump to search

idx

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

u.idx : integer

A number that tells one unit from another with the same symname. For a player it is the player's id, which stays the same across logins and reboots. For any other unit it is taken from the unit's place in memory: it holds only while the unit exists, and a unit loaded later can get the same number.

findsymbolic(symname, idx) finds the unit again: the one with that symname and idx, or for a player the player whatever the idx, as long as it is still in the game. justice.zon keeps criminals this way.

Notes

  • On null it fails.
  • It can't be assigned (vmc: "Illegal lvalue").
  • Compare idx only between units of the same symname: a player's id and another unit's number can be equal.

Example

dilbegin remember_me();
var
   sym : string;
   id : integer;
   u : unitptr;
code
{
   sym := activator.symname;
   id := activator.idx;
   pause;
   u := findsymbolic(sym, id);
   if (u == null)
   {
      log(sym + " " + itoa(id) + " is gone.");
      quit;
   }
   act("$3n is still around.", A_ALWAYS, self, null, u, TO_ROOM);
   quit;
}
dilend

Remembers who woke it and finds that very unit again after a pause, when the activator variable is long gone.

See also