Manual:DIL Manual/wait()

From DikuMUD Wiki
< Manual:DIL Manual
Revision as of 07:21, 15 November 2026 by Agent-mud (talk | contribs) (corrected from the DIL keyword tests (T029-T043))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

wait()

Procedure. Stops the program until an event of the given kinds comes, for which a condition holds.

wait(events : integer, condition)

Every program spends most of its life here. wait() always stops the program; it goes on only with an event of one of the kinds in events (the SFB_ values in vme.h, joined with |) for which condition is true. At each such event the program wakes, the condition is worked out again, and if it is false the program goes back to waiting. The built-ins activator, medium, target, power, argument and command() describe the event, so the condition can test them.

Value Event
SFB_CMD A command typed by someone near the unit, before it runs (it can still be blocked)
SFB_DONE A command that has been carried out
SFB_PRE The step before some actions, e.g. a spell about to hit
SFB_TICK The unit's heartbeat
SFB_RANTIME With SFB_TICK: the tick comes at a random time around the heartbeat
SFB_MSG A message from another program (send, sendto, sendtoall, sendtoalldil)
SFB_COM A combat round
SFB_DEAD A death nearby
SFB_EDIT The end of an editor started with beginedit()
SFB_PROMPT The player's prompt being made

pause; is wait(SFB_TICK | SFB_RANTIME, TRUE), a macro in wmacros.h.

Parameters

Name Type Meaning
events integer The kinds of event to wake for.
condition any True to go on: a non-zero integer, a unit or string that isn't null, a list that isn't empty.

Notes

  • A program read from a file (a room's or object's program when the zone boots, a unit brought back with restore(), a recall program on a player) doesn't run until the first event reaches it, and that event only takes it as far as its wait(): the event itself is lost. A room program waiting for a command misses the first one after a boot. Programs on units that %reset loads start at once and aren't affected.
  • It waits even if the condition is true already.
  • Every event of the given kinds wakes the program, even one the condition then turns down. At every wake each unitptr and extraptr variable that isn't secured becomes null. Save what you need from activator, argument and the rest right after the wait, and secure() a unit you want to keep.
  • Other bits are dropped: wait(SFB_SAVE, ...) never wakes. Use interrupt() for such events.
  • The program also wakes for the events of its interrupt()s, which may jump elsewhere.
  • A condition that fails (a field of a null unit) counts as false. A text field or list entry tested on its own (wait(SFB_TICK, self.title)) counts the wrong way round, as true when the text is empty: compare with "" instead.
  • A program that runs on without a wait or pause for about 52000 instructions is stopped ("had endless loop" in the zone log).

Example

dilbegin greeter();
var
   pc : unitptr;
code
{
   heartbeat := PULSE_SEC * 3;
   :start:
   wait(SFB_CMD, command("say") and (activator.type == UNIT_ST_PC) and
                 ("hello" in argument));
   pc := activator;
   secure(pc, start);
   pause;                    // let the player's words show first
   exec("say Welcome, " + pc.name + "!", self);
   unsecure(pc);
   goto start;
}
dilend

An NPC that welcomes a player who says hello.

See also