Item properties in conditions
ScriptExpressionItemSelector · signed byte, sign-extended; follows
SCRIPT_EXPR_HELD_ITEM or SCRIPT_EXPR_LAST_USED_ITEM in a
condition expression
Test a condition ·
ItemRuntime · Scripts
A script condition can look at the item the player holds, or at the item that has just been used, and test its index, type, value or name. This byte chooses which property the condition reads. Each of the two item tokens accepts only some of the selectors.1
"Held item" and "last-used item" are inferred names: the helper picks a held or selected item.
typedef enum ScriptExpressionItemSelector {
SCRIPT_EXPR_ITEM_INDEX = 0xf5, /* Item index (both tokens). */
SCRIPT_EXPR_ITEM_TYPE = 0xe1, /* ItemRuntime type_raw, sign-extended (both tokens). */
SCRIPT_EXPR_ITEM_VALUE = 0xf6, /* ItemRuntime value_raw, sign-extended (both tokens). */
SCRIPT_EXPR_ITEM_UNIDENTIFIED_NAME_CONTAINS = 0xd0, /* Held item only. */
SCRIPT_EXPR_ITEM_IDENTIFIED_NAME_CONTAINS = 0xcf, /* Held item only. */
SCRIPT_EXPR_ITEM_TYPE_PROPERTIES = 0xdc /* Last-used item only. */
} ScriptExpressionItemSelector;
| Selector | Held item | Last-used item | Value pushed |
|---|---|---|---|
SCRIPT_EXPR_ITEM_INDEX | yes | yes | The item index. |
SCRIPT_EXPR_ITEM_TYPE | yes | yes | Byte +4 of the item. |
SCRIPT_EXPR_ITEM_VALUE | yes | yes | value_raw of the item. |
SCRIPT_EXPR_ITEM_UNIDENTIFIED_NAME_CONTAINS | yes: a u8 length, then that many bytes | no | 1 if the upper-cased name selected by byte +0 contains the upper-cased string, otherwise 0. |
SCRIPT_EXPR_ITEM_IDENTIFIED_NAME_CONTAINS | yes: a u8 length, then that many bytes | no | The same test with the name selected by identified_name_index. |
SCRIPT_EXPR_ITEM_TYPE_PROPERTIES | no | yes | The properties_raw word of the item's ItemTypeRuntime entry, masked with 0x7f. |
A selector that its token does not accept pushes nothing and consumes no operand, which unbalances the expression stack.
Which item is tested
- Held item. A helper picks it: depending on a control byte, it is either
the item held with the mouse, or the item in the hand slot selected for the
active character in
CharacterRuntime.2 - Last-used item. The game stores the used item only while it sends
BLOCK_EVENT_ITEM_USED, then clears it; a byte search found no other writer.3
When no item is held (index zero), the evaluator does not check it and reads item entry 0, whose original record has type 0 and value 0. This happens whenever such a test runs while nothing is held, for example when the player clicks a wall decoration with an empty pointer.
Name tests
The length byte is the number of bytes that the evaluator skips after the
string. The string itself is copied up to its first zero byte into a 36-byte
buffer without a length check, so a script string of 36 or more bytes before
its zero byte would overflow it. The names are the 35-byte name slots loaded
from ITEM.DAT. Upper-casing affects only the ASCII
letters a to z, and an empty script string always matches.4
Sources
Locations refer to the game executable reference.