Skip to main content

Timed scripts

The engine · Timed updates · Scripts · INF schema

In brief​

Two features of a level run scripts without the party touching anything. Timed block scripts send a timer event to a block at a regular interval. The step-triggered script runs the script of block [00:00] once the party has walked a given number of steps. Both are set up from the level's INF file each time the level loads, and both are checked once per pass of the game loop, right after the timed updates.

Positions are written [XX:YY], column then row, both counted from 00; the block index is YY × 32 + XX.

What the game checks after the timed updates of a pass. If the step limit is nonzero and the step count is above it, a step-count event goes to block [00:00] and the step counter returns to 0. Then, for each timed entry, if the counter has strictly passed its deadline, a timer event goes to its block and its next deadline becomes the counter plus its interval.
The step-triggered script comes first; a timed script fires once its deadline is strictly past.

Timed block scripts​

A sublevel can list timed events in its INF data: each entry names a block and an interval. When the level loads, each interval is multiplied by 18 and kept as a signed 16-bit value, so it counts in units of 18 ticks, just under a second, and the first deadline is the current counter plus that value.1

At each check, for every entry whose deadline the shared counter has strictly passed, the game:

  1. sends BLOCK_EVENT_TIMER to the entry's block; the block's binding and event bits still decide whether a script actually runs;
  2. sets the next deadline to the current counter plus the interval.

Because the next deadline starts from the current counter, a late check never triggers the event several times to catch up.1

The timer check runs once per pass of the game loop, after the timed updates and the step-triggered script. Like every deadline, the timers wait during pauses.2

Long intervals. Only the low 16 bits of the product are kept, read as signed, so an INF interval n gives a period of (18 × n) mod 65 536 ticks, read as a signed number:

INF intervalPeriod
00: the event is sent at every tick
1 to 1 82018 × n ticks, up to 32 760 (about 30 minutes)
1 821 to 3 640Negative: the event is sent at every pass of the game loop
3 641 to 5 46118 × n − 65 536 ticks: a short period again, and so on

With a negative period − k, the deadline falls k ticks before the counter, so it has always passed, except while the counter itself is below k, in the first half hour of counted time, when the 32-bit deadline wraps round to a value the counter never reaches and the event is never sent. The counter itself would wrap only after 2³² ticks, about seven and a half years of play. The original levels use intervals of 1 to 180 only, 18 to 3 240 ticks; none of these cases arises in them.1

Step-triggered script​

A sublevel can also run a script after a number of party moves, given by the step limit of its INF sublevel record (steps_until_script). When the sublevel loads, the game stores that value and resets the party's step counter; every party move adds one to the counter.3

Just before the script timers, the periodic update checks the counter. If the stored value is nonzero and the counter is strictly greater, it sends BLOCK_EVENT_STEP_COUNT to the block at [00:00] and resets the counter to zero, whether or not a script ran.3

if steps_until_script != 0 and step_counter > steps_until_script:
dispatch(block = [00:00], event = BLOCK_EVENT_STEP_COUNT)
step_counter = 0

No enabling bit is needed: the event runs the [00:00] script whenever that block has one. In the 16 reference INF files, the 11 levels whose first sublevel record gives a nonzero value, from 20 to 100 steps, are exactly those that bind a script to [00:00].3

Sources​

Locations refer to the game executable reference; comparative sources are listed in the technical references.

Footnotes​

  1. Timer list loader into the timer records; script timers and the block event dispatcher; the shared counter. ↩ ↩2 ↩3

  2. Timed-callback processing, called by the update loop; the counter is advanced by the timer interrupt. ↩

  3. Step-script limit loader (the step limit and the step counter); counter increment in move the party; step trigger, called from timed-callback processing. Comparative source: REF-SCUMM-012, updateScriptTimers. The statistics come from the sublevel records of the 16 reference INF files. ↩ ↩2 ↩3