Manual:DIL Manual/heartbeat

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

heartbeat

Variable (integer, read/write).

heartbeat : integer

How often the program's tick comes, in quarter seconds: PULSE_SEC (4, vme.h) is one second. A program waiting for SFB_TICK, and every pause, waits for it. Each program has its own heartbeat; a new one starts at PULSE_SEC.

Notes

  • Write it as a multiple of PULSE_SEC (or WAIT_SEC, the same 4): heartbeat := PULSE_SEC * 30; is 30 seconds.
  • The new value takes effect when the program next waits. Anything below PULSE_SEC is raised to PULSE_SEC: no program ticks more than once a second.
  • It is kept in 16 bits without a sign: the longest heartbeat is 65535 (about 4.5 hours), larger values wrap round, and a negative one becomes a very long heartbeat. Reading it back gives a negative number for values from 32768 up.
  • pause waits for the next tick, so with heartbeat := PULSE_SEC * 90 a pause can take 90 seconds, and under priority the unit's other programs wait all that time. Shorten the heartbeat around pauses, as the example does. Just after a change the next tick comes at a random point between half and one and a half heartbeats (SFB_RANTIME in pause).
  • A function called as name@zone shares its caller's heartbeat; quests.zon's functions save it and put it back (heartbeat := phb;).
  • On a running game a god's wtimewarp makes the ticks come without delay, to try out long heartbeats.

Example

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

   :start:
   wait(SFB_TICK, TRUE);
   heartbeat := PULSE_SEC * 3;
   exec("say Brooms! Fine brooms!", self);
   pause;
   exec("say Two copper each!", self);
   heartbeat := PULSE_SEC * 60;
   goto start;
}
dilend

A street seller who calls out once a minute, with a three second pause between the two lines.

See also