Manual:DIL Manual/self
Jump to navigation
Jump to search
Contents
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
dilbeginwritten 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'sself, since it runs inside the caller's program.
Notes
selfis never cleared by a wait or a pause and needs no secure(). Unit variables are cleared at every wake;selfisn't one.- It can't be assigned (
self := uis "Illegal lvalue"). - When the unit is destroyed, its programs end with it. A program that destroys its own unit should
quitright afterdestroy(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.