Manual:DIL Manual/self

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

self

Variable (unitptr, read-only).

self : unitptr

The unit the program runs on:

  • a template copied with dilcopy: the unit it was copied onto;
  • a dilbegin written inside a unit's definition: that unit;
  • a player command written in DIL (func = in commands.def): the character who typed it;
  • a spell's DIL: the caster;
  • a function called as name@zone: the caller's self, since it runs inside the caller's program.

Notes

  • self is never cleared by a wait or a pause and needs no secure(). Unit variables are cleared at every wake; self isn't one.
  • It can't be assigned (self := u is "Illegal lvalue").
  • When the unit is destroyed, its programs end with it. A program that destroys its own unit should quit right after destroy(self), as death.zon's rot_head does.
  • The usual tests: self.position (asleep, fighting), self.outside (where it is), exec("say ...", self) to make an NPC act.

Example

dilbegin crier();
code
{
   heartbeat := PULSE_SEC * 60;

   :start:
   wait(SFB_TICK, TRUE);
   if (self.position != POSITION_STANDING)
      goto start;
   exec("say Hear ye! " + self.name + " brings news to " + self.outside.title + "!", self);
   goto start;
}
dilend

An NPC that, once a minute when standing, calls out its own name and the title of the room it is in.

See also