Manual:DIL Manual/wait()
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
- 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
unitptrandextraptrvariable that isn't secured becomes null. Save what you need fromactivator,argumentand the rest right after thewait, andsecure()a unit you want to keep. - Other bits are dropped:
wait(SFB_SAVE, ...)never wakes. Useinterrupt()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
waitorpausefor 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.