Set walls or a direction
SCRIPT_SET · opcode 0xff · 2 to 6 bytes
Script virtual machine · Opcode list · Scripted wall assignment
Replaces the walls of a block, or one of its sides, with a given wall reference; a third form stores a direction value.
Encoding
Offsets count from the opcode byte. Words are little-endian. The byte at
offset 1 is a ScriptSetTarget and decides
what follows.
| Selector | Byte | Operands after the selector | Size |
|---|---|---|---|
SCRIPT_SET_BLOCK_WALLS | 0xf7 | block: u16le, wall: u8 | 5 bytes |
SCRIPT_SET_BLOCK_SIDE | 0xe9 | block: u16le, side: s8, wall: u8 | 6 bytes |
SCRIPT_SET_DIRECTION | 0xed | direction: s8 | 3 bytes |
| Any other value | — | None | 2 bytes |
Example (constructed, not from a level): ff f7 ab 00 1a gives all four sides
of block 171 the wall reference 26, WALL_REFERENCE_CLEARED_ON_ENTRY of
SpecialWallReference. Block 171 is position [11:05], with
block = YY × 32 + XX.
Behavior
- All walls.
wallis written to the four wall references of the block'sLevelBlockRuntime. - One side.
wallis written to the reference selected byside. - Direction. The sign-extended
directionbecomes the party's facing, the value the turn commands change andSCRIPT_EXPR_PARTY_DIRECTIONreads. Unlike Turn, the instruction requests no redraw. Of the 90 reference instructions, 40 come right after a party move; the others are followed, within eight instructions of straight code, by a scene redraw (31), a dialogue (11), a party move (5) or a sequence (3).
After a wall write, the handler passes the block to a helper that marks the view for redrawing when the block is one of the 15 blocks in view ahead of the party. Neighboring blocks are not changed.1
The temporary level state saved on a level change collects these wall references, so a level restored from it keeps the changes; see scripted wall assignment.
Edge cases
sideis not range-checked: the handler writeswallat bytesideof the block'sLevelBlockRuntimeentry, counted from its first wall and read as signed: 0–3 are the four walls, in the order of the structure page, and the other values from −128 to 127 reach the entry's other fields — 8 and 9 are itsscript_offset— and the ten-byte entries around it. The reference scripts use 0–3 only.directionis not reduced to 0–3. Movement and drawing use the facing to index four-entry tables, which a value outside 0–3 reads past, until the next turn brings the facing back to 0–3. The reference scripts use 0 to 3 only.- The handler skips unlisted selectors after reading them. See also unexpected values.
Observed use
The reference scripts use SCRIPT_SET_BLOCK_WALLS 592 times,
SCRIPT_SET_BLOCK_SIDE 166 times and SCRIPT_SET_DIRECTION 90 times, with
direction 0 (29 times), 1 (23), 2 (20) and 3 (18).