Skip to main content

Toggle walls or a door

SCRIPT_TOGGLE · opcode 0xfe · 4 to 7 bytes

Script virtual machine · Opcode list · Scripted wall toggling

Switches the walls of a block, or one of its sides, between two wall references; a third form opens a closed door or closes an open one.

Encoding​

Offsets count from the opcode byte. Words are little-endian. The byte at offset 1 is a ScriptToggleTarget and decides what follows.

SelectorByteOperands after the selectorSize
SCRIPT_TOGGLE_BLOCK_WALLS0xf7block: u16le, first: u8, second: u86 bytes
SCRIPT_TOGGLE_BLOCK_SIDE0xe9block: u16le, side: s8, first: u8, second: u87 bytes
SCRIPT_TOGGLE_DOOR0xeablock: u16le4 bytes

Example (constructed, not from a level): fe f7 ab 00 1a 1b switches block 171 between wall references 26 (WALL_REFERENCE_CLEARED_ON_ENTRY of SpecialWallReference) and 27. Block 171 is position [11:05], with block = YY × 32 + XX.

Behavior​

The two wall forms choose the new reference the same way:1

if current_reference == first:
new_reference = second
else:
new_reference = first

SCRIPT_TOGGLE_BLOCK_SIDE applies this to the selected side. SCRIPT_TOGGLE_BLOCK_WALLS compares only the first side of the block and writes the result to all four sides, even if the other sides differed. A reference equal to neither value becomes first. After the write, the handler calls the same block-update helper as Set walls or a direction.

SCRIPT_TOGGLE_DOOR is skipped when the block's occupancy is nonzero or the party stands in it, like Close a door. If a door operation is already recorded for the block, it is reversed; otherwise the direction is chosen from the runtime properties of the door's wall. The request then goes to the shared door routine; see scripted doors.2

Edge cases​

  • side is not range-checked: as for Set walls, the byte compared and written is byte side of the block's entry, read as signed, and can be another field or another block's.
  • Other selectors are skipped after the selector: the instruction is 2 bytes long and has no effect.
  • SCRIPT_TOGGLE_DOOR refuses to open as well as to close while the block is occupied. With no operation recorded, it closes a door whose leading face lets the party pass (the open door) and opens any other; see scripted doors.

Observed use​

The reference scripts use SCRIPT_TOGGLE_BLOCK_WALLS 57 times and SCRIPT_TOGGLE_DOOR 22 times; SCRIPT_TOGGLE_BLOCK_SIDE does not occur.

Sources​

Footnotes​

  1. Handler for 0xfe and the block-update helper. Comparative source: oeob_toggleWallState in REF-SCUMM-003. Statistics come from decoding the scripts reachable in the 16 reference INF files. ↩

  2. Door toggle wrapper, the shared door routine and the wall properties. ↩