Skip to main content

Set a flag

SCRIPT_SET_FLAGS · opcode 0xf7 · 2 to 4 bytes

Script virtual machine · Opcode list · Script flags

Sets a bit of the level's or the game's flags, provokes a monster, or turns on a control setting. Conditions read these flags back with Test a condition; Clear a flag is the reverse operation.

Encoding​

Offsets count from the opcode byte. The byte at offset 1 is a ScriptFlagTarget and decides what follows.

SelectorByteOperands after the selectorSize
SCRIPT_FLAG_TARGET_LEVEL0xefbit_index: s83 bytes
SCRIPT_FLAG_TARGET_GLOBAL0xf0bit_index: s83 bytes
SCRIPT_FLAG_TARGET_MONSTER0xf3monster_slot: s8, bit_index: s84 bytes
SCRIPT_FLAG_TARGET_RUN_VARIABLE0xe4None2 bytes
SCRIPT_FLAG_TARGET_REST_ALLOWED0xd1None2 bytes
Any other value—None; no effect2 bytes

Example (constructed, not from a level): f7 ef 03 sets bit 3 of the current level's flags.

Behavior​

SelectorEffect
SCRIPT_FLAG_TARGET_LEVELSets bit bit_index of the 32-bit flag value kept for the current level.
SCRIPT_FLAG_TARGET_GLOBALSets bit bit_index of the 32-bit flag value shared by all levels.
SCRIPT_FLAG_TARGET_MONSTERSets bit bit_index of the selected monster's runtime flags and switches it to MONSTER_MODE_PURSUE.
SCRIPT_FLAG_TARGET_RUN_VARIABLEWrites 1 to the run variable read by SCRIPT_EXPR_RUN_VARIABLE.
SCRIPT_FLAG_TARGET_REST_ALLOWEDAllows the party to rest.

The monster form does not change the monster's stored destination. The reference scripts always set bit 0, MONSTER_RUNTIME_PROVOKED of MonsterRuntimeFlags, which damage also sets: the monster then pursues the party. See setting a monster flag and MonsterMode.1

The rest setting survives level changes and is saved with the game; see script flags.

Edge cases and unknowns​

  • bit_index values outside 0–31 (0–7 for a monster) set no bit, except some larger or negative values, whose effect depends on the processor; see bit numbers. The reference scripts use 0–31, and only bit 0 for monsters.
  • monster_slot is multiplied by the 30-byte slot size without a range check: values outside 0–29 write a byte outside the monster slots and clear another byte 14 bytes before it.
  • Other selector values are skipped after the selector; whether they are valid is not established.

Observed use​

The reference scripts use SCRIPT_FLAG_TARGET_LEVEL 292 times, SCRIPT_FLAG_TARGET_MONSTER 16 times, SCRIPT_FLAG_TARGET_GLOBAL 10 times and SCRIPT_FLAG_TARGET_REST_ALLOWED 7 times. SCRIPT_FLAG_TARGET_RUN_VARIABLE does not occur.

Sources​

Footnotes​

  1. Handler for 0xf7, the level flags, the global flags, the run variable and the rest setting. Comparative source: oeob_setFlags in REF-SCUMM-003. Statistics come from decoding the scripts reachable in the 16 reference INF files. ↩