Difference between revisions of "Manual:DIL Manual/self"
Jump to navigation
Jump to search
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| Line 1: | Line 1: | ||
| − | + | = self = | |
| − | + | '''Variable''' (unitptr, read-only). | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | self : unitptr | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | The unit the program runs on: | |
| + | * a template copied with <code>dilcopy</code>: the unit it was copied onto; | ||
| + | * a <code>dilbegin</code> written inside a unit's definition: that unit; | ||
| + | * a player command written in DIL (<code>func =</code> in commands.def): the character who typed it; | ||
| + | * a spell's DIL: the caster; | ||
| + | * a function called as <code>name@zone</code>: the caller's <code>self</code>, since it runs inside the caller's program. | ||
| + | |||
| + | == Notes == | ||
| + | * <code>self</code> is never cleared by a wait or a pause and needs no secure(). Unit variables are cleared at every wake; <code>self</code> isn't one. | ||
| + | * It can't be assigned (<code>self := u</code> is "Illegal lvalue"). | ||
| + | * When the unit is destroyed, its programs end with it. A program that destroys its own unit should <code>quit</code> right after <code>destroy(self)</code>, as death.zon's rot_head does. | ||
| + | * The usual tests: <code>self.position</code> (asleep, fighting), <code>self.outside</code> (where it is), <code>exec("say ...", self)</code> to make an NPC act. | ||
| + | |||
| + | == Example == | ||
| + | <pre> | ||
| + | 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 | ||
| + | </pre> | ||
| + | An NPC that, once a minute when standing, calls out its own name and the title of the room it is in. | ||
| + | |||
| + | == See also == | ||
| + | * [[Manual:DIL Manual/activator|activator]] | ||
| + | * [[Manual:DIL Manual/exec()|exec()]] | ||
| + | * [[Manual:DIL Manual/dilcopy()|dilcopy()]] | ||
| + | * [[Manual:DIL Manual/Built-In Variables|Built-In Variables]] | ||
Latest revision as of 23:18, 14 November 2026
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.