Manual:DIL Manual/heartbeat
Jump to navigation
Jump to search
Contents
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(orWAIT_SEC, the same 4):heartbeat := PULSE_SEC * 30;is 30 seconds. - The new value takes effect when the program next waits. Anything below
PULSE_SECis raised toPULSE_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.
pausewaits for the next tick, so withheartbeat := PULSE_SEC * 90a pause can take 90 seconds, and underprioritythe 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_RANTIMEinpause).- A function called as
name@zoneshares its caller's heartbeat; quests.zon's functions save it and put it back (heartbeat := phb;). - On a running game a god's
wtimewarpmakes 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.