Skip to main content

Flag operation targets

ScriptFlagTarget · 1 byte, first operand of Set a flag and Clear a flag

Scripted characters, flags and messages · Script instructions

Scripts keep state in flags: bits of the current level, bits kept across the whole game, a monster's state, a scratch variable, and whether the party may rest. This byte chooses which one the instruction changes. The two instructions accept slightly different sets of targets.1

Other values are unknown.

typedef enum ScriptFlagTarget {
SCRIPT_FLAG_TARGET_LEVEL = 0xef, /* A bit of the current level's flags. */
SCRIPT_FLAG_TARGET_GLOBAL = 0xf0, /* A bit of the global flags. */
SCRIPT_FLAG_TARGET_MONSTER = 0xf3, /* A bit of a monster slot's flags; set only. */
SCRIPT_FLAG_TARGET_RUN_VARIABLE = 0xe4, /* Write 1 (set) or 0 (clear) to the run variable. */
SCRIPT_FLAG_TARGET_REST_ALLOWED = 0xd1 /* Set allows resting; clear forbids it. */
} ScriptFlagTarget;

Operands​

  • SCRIPT_FLAG_TARGET_LEVEL and SCRIPT_FLAG_TARGET_GLOBAL take one bit-index byte. The global bits are described in global script flags.
  • SCRIPT_FLAG_TARGET_MONSTER takes a monster slot selector and a bit index.
  • SCRIPT_FLAG_TARGET_RUN_VARIABLE and SCRIPT_FLAG_TARGET_REST_ALLOWED take no operand, although the clear handler reads the following byte before choosing its branch.

See script flags for the operations.

Provoking a monster​

With SCRIPT_FLAG_TARGET_MONSTER, the handler sets the bit in the monster's state flags and switches the monster to MONSTER_MODE_PURSUE, without changing its stored destination. All reference scripts use bit 0, MONSTER_RUNTIME_PROVOKED, which makes the monster pursue the party. Valid operand ranges are unknown. See setting a monster flag.

Forbidding rest​

SCRIPT_FLAG_TARGET_REST_ALLOWED controls one byte that the rest routine checks before letting the party rest. Setting the target writes 0, which allows resting; clearing it writes 1, and the rest routine then refuses with a message that it is not safe to rest. It is the first of the tests made before a rest; see resting.2

No other code writes this byte, and it starts at 0. A level change leaves it unchanged: a prohibition set on one level stays in force on the next, until a script allows resting again. The byte is part of the level and party state that the game writes to its saved-game file and reads back, so it also survives saving and reloading.3

Sources​

Locations refer to the game executable reference.

Footnotes​

  1. Set flags and clear flags handlers, with the bit-shift helper. Comparative source: oeob_setFlags and oeob_removeFlags in REF-SCUMM-003. ↩

  2. Rest permission byte, read by the rest routine. Comparative source: preventRest in REF-SCUMM-012. A byte scan finds no other reader or writer; it cannot exclude a write through a computed address. ↩

  3. The byte lies in the level and party state block, written by the state file writer and read back by the state file reader: the saved game. ↩