Skip to main content

Delete items

SCRIPT_DELETE_ITEM · opcode 0xed · 2 or 4 bytes

Script virtual machine · Opcode list · Scripted item removal

Removes items from the game: the item in the player's hand, every item of a block, or the items of one type in a block.

Encoding​

Offsets count from the opcode byte. Words are little-endian. The signed byte at offset 1 is either a special value of ScriptDeleteTarget or an item type.

SelectorByteOperands after the selectorSize
SCRIPT_DELETE_HELD_ITEM0xffNone2 bytes
SCRIPT_DELETE_ALL_IN_BLOCK0xfeblock: u16le4 bytes
An ItemTypeany otherblock: u16le4 bytes

Example (constructed, not from a level): ed 28 ab 00 deletes the items of type ITEM_TYPE_GEM (40) in block 171. Block 171 is position [11:05], with block = YY × 32 + XX.

Behavior​

  • Held item. The item selected by the held-item routine is marked as removed. Which item that is depends on the game's control state: the item held with the mouse, or the selected character's hand slot. The item is freed first, then its holder is emptied: the mouse pointer or, in keyboard control, the selected slot, through the same rule as putting an item there.
  • Block. The handler walks the block's item chain. Each item whose signed type matches the selector (any item for SCRIPT_DELETE_ALL_IN_BLOCK) is marked as removed and unlinked; the items that do not match are linked into a new chain for the block. Items of every position are deleted, including those in flight and in a niche.1

A removed item has its location set to −1 and its links cleared; see ItemRuntime. No event is sent and no redraw is requested.

Edge cases and unknowns​

  • Because the type is a signed byte, item types 254 and 255 read as the selectors SCRIPT_DELETE_ALL_IN_BLOCK and SCRIPT_DELETE_HELD_ITEM and cannot be selected as filters.
  • Any item type is accepted and only compared; a chain that never returns to its head is walked forever and the game stops responding.

Anomaly

ANOMALY-132 — In keyboard control, deleting the held item when it is a cursed item in a hand frees the item, then fails to empty the hand. The placement rule refuses to take it out, so the game prints that the weapon cannot be released (for a cursed weapon) and that the item cannot be put there, and the hand keeps the freed item. The next item created takes that free entry, and the hand then holds the new item. This cannot happen with the original data: every held-item deletion first tests the item's type, and no cursed item has one of the tested weapon types. A faithful reimplementation frees the item before applying the placement rule.1

Anomaly

ANOMALY-133 — Deleting the items of a block also frees an item in flight there, but its flight goes on. At its next step the item is linked into the next block, on the current level, and becomes a flying item again. If a new item has been created in the freed entry in between, the flight carries off that new item: it flies on in the next block while the block where it was put still lists it. A faithful reimplementation leaves the flight running.1

Anomaly

ANOMALY-149 — Deleting the held item when nothing is held treats item 0, the value of an empty holder, as an item: the location of item entry 0 becomes −1, the mark of a free entry. The chain insertion, by contrast, ignores item 0. Entry 0 is never handed out, since item creation searches entries 1 to 599, so nothing visible follows (inferred). This is latent: each of the 76 reference instructions of this form comes after a test of the held item's type or name that item 0 does not pass. A faithful reimplementation writes −1 to entry 0 and does not reuse that entry.1

Observed use​

The reference scripts use SCRIPT_DELETE_HELD_ITEM 76 times, the type filter ITEM_TYPE_GEM 16 times, the type filter ITEM_TYPE_KEY 9 times and SCRIPT_DELETE_ALL_IN_BLOCK 4 times.

Sources​

Footnotes​

  1. Handler for 0xed, the held-item removal, the held-item selector, the block item deletion and the chain insertion, the item duplication, the placement check and the flight step. Comparative source: oeob_deleteItem in REF-SCUMM-003. Statistics come from decoding the scripts reachable in the 16 reference INF files. ↩ ↩2 ↩3 ↩4