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.
| Selector | Byte | Operands after the selector | Size |
|---|---|---|---|
SCRIPT_FLAG_TARGET_LEVEL | 0xef | bit_index: s8 | 3 bytes |
SCRIPT_FLAG_TARGET_GLOBAL | 0xf0 | bit_index: s8 | 3 bytes |
SCRIPT_FLAG_TARGET_RUN_VARIABLE | 0xe4 | None | 2 bytes |
SCRIPT_FLAG_TARGET_REST_ALLOWED | 0xd1 | None | 2 bytes |
| Any other value | — | One byte, read and ignored | 3 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
| Selector | Effect |
|---|---|
SCRIPT_FLAG_TARGET_LEVEL | Clears bit bit_index of the 32-bit flag value kept for the current level. |
SCRIPT_FLAG_TARGET_GLOBAL | Clears bit bit_index of the 32-bit flag value shared by all levels. |
SCRIPT_FLAG_TARGET_RUN_VARIABLE | Writes 0 to the run variable read by SCRIPT_EXPR_RUN_VARIABLE. |
SCRIPT_FLAG_TARGET_REST_ALLOWED | Makes 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_indexvalues 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.