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.
| Selector | Byte | Operands after the selector | Size |
|---|---|---|---|
SCRIPT_TOGGLE_BLOCK_WALLS | 0xf7 | block: u16le, first: u8, second: u8 | 6 bytes |
SCRIPT_TOGGLE_BLOCK_SIDE | 0xe9 | block: u16le, side: s8, first: u8, second: u8 | 7 bytes |
SCRIPT_TOGGLE_DOOR | 0xea | block: u16le | 4 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
sideis not range-checked: as for Set walls, the byte compared and written is bytesideof 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_DOORrefuses 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.