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.
| 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_MONSTER | 0xf3 | monster_slot: s8, bit_index: s8 | 4 bytes |
SCRIPT_FLAG_TARGET_RUN_VARIABLE | 0xe4 | None | 2 bytes |
SCRIPT_FLAG_TARGET_REST_ALLOWED | 0xd1 | None | 2 bytes |
| Any other value | — | None; no effect | 2 bytes |
Example (constructed, not from a level): f7 ef 03 sets bit 3 of the current
level's flags.
Behavior
| Selector | Effect |
|---|---|
SCRIPT_FLAG_TARGET_LEVEL | Sets bit bit_index of the 32-bit flag value kept for the current level. |
SCRIPT_FLAG_TARGET_GLOBAL | Sets bit bit_index of the 32-bit flag value shared by all levels. |
SCRIPT_FLAG_TARGET_MONSTER | Sets bit bit_index of the selected monster's runtime flags and switches it to MONSTER_MODE_PURSUE. |
SCRIPT_FLAG_TARGET_RUN_VARIABLE | Writes 1 to the run variable read by SCRIPT_EXPR_RUN_VARIABLE. |
SCRIPT_FLAG_TARGET_REST_ALLOWED | Allows 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_indexvalues 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_slotis 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.