Skip to main content

Clear a flag

SCRIPT_CLEAR_FLAGS · opcode 0xf5 · 2 or 3 bytes

Script virtual machine · Opcode list · Script flags

Clears a bit of the level's or the game's flags, or turns off a control setting. It is the reverse of Set a flag.

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_RUN_VARIABLE0xe4None2 bytes
SCRIPT_FLAG_TARGET_REST_ALLOWED0xd1None2 bytes
Any other value—One byte, read and ignored3 bytes

SCRIPT_FLAG_TARGET_MONSTER is handled by Set a flag only: here it is one of the other values, with no effect. A clear written like the four-byte set form leaves its bit number as the next command byte, which is skipped: it still has no effect.

For the two control selectors, the handler reads the byte that follows the selector before returning a length that excludes it. The instruction is still 2 bytes long; the extra read matters only for a script that ends right after the selector.1

Example (constructed, not from a level): f5 d1 forbids resting.

Behavior​

SelectorEffect
SCRIPT_FLAG_TARGET_LEVELClears bit bit_index of the 32-bit flag value kept for the current level.
SCRIPT_FLAG_TARGET_GLOBALClears bit bit_index of the 32-bit flag value shared by all levels.
SCRIPT_FLAG_TARGET_RUN_VARIABLEWrites 0 to the run variable read by SCRIPT_EXPR_RUN_VARIABLE.
SCRIPT_FLAG_TARGET_REST_ALLOWEDMakes the rest command refuse to rest.

The rest setting survives level changes and is saved with the game. On level 7, for example, a clear of this setting precedes a lightning trap; see script flags.1

Edge cases and unknowns​

  • bit_index values outside 0–31 clear no bit, except some values from 48 upwards (or negative), whose effect depends on the processor; see bit numbers. The reference scripts use 0–31.
  • Other selector values have no effect, but take one more byte than with Set a flag, which skips them after the selector. Whether they are valid is not established.

Observed use​

The reference scripts use SCRIPT_FLAG_TARGET_LEVEL 53 times, SCRIPT_FLAG_TARGET_GLOBAL 12 times and SCRIPT_FLAG_TARGET_REST_ALLOWED 10 times.

Sources​

Footnotes​

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