# new RezInventory()
Manages a collection of slots that can hold items.
An inventory is a container system that organizes items into typed slots. Each slot can accept items of a specific type and may have capacity limits. Inventories can be owned by actors, enabling equipment systems with effects.
Key features:
- Typed Slots: Each slot accepts only items of a matching type
- Capacity: Slots can have size limits based on item sizes
- Weight: Inventories can have an overall
max_weight, checked against the totalweightof all items they contain - Effects: Items can apply effects to the inventory's owner when inserted
- Events: Triggers events on insert/remove for items, slots, and inventory
Slots are defined as a binding list on the slots attribute where each
binding key (prefix) is the slot position name and the value is a reference
to a @slot element that defines the slot's type configuration. Multiple
positions can share the same slot type definition.
Define in Rez:
@inventory player_inv {
slots: [weapon: #s_weapon, armor: #s_armor]
initial_weapon: [#item_sword]
}
Example
Add an item at runtime
const inv = $("player_inv");
if(inv.canAddItemForSlot("weapon", "item_axe").result) {
inv.addItemToSlot("weapon", "item_axe");
}
Extends
Methods
# static addItemToSlot(slotBinding, itemId) → {RezDecision}
Adds the given item to the given slot if canAddItemForSlot allows
it, notifying inventory, slot & item and applying effects. Callers may inspect
the returned decision; callers that ignore it simply get a no-op on refusal.
Parameters:
| Name | Type | Description |
|---|---|---|
slotBinding |
string
|
|
itemId |
string
|
the decision from canAddItemForSlot; when it is yes the
item has been inserted, otherwise the slot is unchanged and the decision carries
the reason and failed_on data.
Example
const d = inv.addItemToSlot("weapon", "item_axe");
if(d.wasNo) showMessage(d.reason);
# static addSlot(slotBinding, slotId)
add a new slot to the inventory
Parameters:
| Name | Type | Description |
|---|---|---|
slotBinding |
string
|
the binding prefix for the slot position |
slotId |
string
|
the slot element id (unused but kept for API clarity) |
# static appendItemToSlot(slotBinding, itemId) → {RezDecision}
Appends the given item to the given slot through the validated add path (fires events, applies effects, and may refuse). Retained for API compatibility; previously this was an unconditional raw push.
Parameters:
| Name | Type | Description |
|---|---|---|
slotBinding |
string
|
|
itemId |
string
|
the decision from addItemToSlot
# static appendToSlot(slotBinding, itemOrItems) → {Array.<RezDecision>}
add either a single item_id or an array of item_ids to the slot, each through the validated add path.
Parameters:
| Name | Type | Description |
|---|---|---|
slotBinding |
string
|
|
itemOrItems |
string
|
array
|
either an item_id or array of item_id's to append to the slot |
a decision for each item, in order
Array.<RezDecision>
# static applyEffects(slotBinding, itemId) → {boolean}
Parameters:
| Name | Type | Description |
|---|---|---|
slotBinding |
string
|
|
itemId |
string
|
whether the effect was applied
boolean
# static canAddItemForSlot(slotBinding, itemId) → {RezDecision}
Parameters:
| Name | Type | Description |
|---|---|---|
slotBinding |
string
|
|
itemId |
string
|
decision object with result
# static canRemoveItemFromSlot(slotBinding, itemId) → {RezDecision}
Parameters:
| Name | Type | Description |
|---|---|---|
slotBinding |
string
|
|
itemId |
string
|
decision object with result, defaulting to yes
# static clearSlot(slotBinding)
remove all items from the given slot, removing any effects granted by those items
Parameters:
| Name | Type | Description |
|---|---|---|
slotBinding |
string
|
# static containsItem(itemId) → {string|undefined}
Parameters:
| Name | Type | Description |
|---|---|---|
itemId |
string
|
binding prefix of the slot containing the item, or undefined
string
|
undefined
# static countItemsInSlot(slotBinding) → {integer}
Parameters:
| Name | Type | Description |
|---|---|---|
slotBinding |
string
|
number of items in the given slot
integer
# static disableSlot(slotBinding)
Disables the slot so no further items can be added to it.
Parameters:
| Name | Type | Description |
|---|---|---|
slotBinding |
string
|
the binding prefix identifying the slot position |
Example
$("player_equip").disableSlot("ring2");
# static elementInitializer()
called as part of the init process this creates the initial inventory slots
# static enableSlot(slotBinding)
Enables the slot so items can be added to it.
Parameters:
| Name | Type | Description |
|---|---|---|
slotBinding |
string
|
the binding prefix identifying the slot position |
Example
$("player_equip").enableSlot("ring2");
# static getFirstItemForSlot(slotBinding) → {string}
Parameters:
| Name | Type | Description |
|---|---|---|
slotBinding |
string
|
id of first item in the slot
string
# static getItemsForSlot(slotBinding) → {array}
Parameters:
| Name | Type | Description |
|---|---|---|
slotBinding |
string
|
contents of the specified slot
array
# static getSlot(name) → {object}
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string
|
the binding prefix identifying the slot position |
reference to the slot element for this binding, or throws if the binding does not exist in this inventory.
object
# static getSlots() → {array}
array of {prefix, slot} objects for every slot position in this inventory
array
Example
for(const {prefix, slot} of inv.getSlots()) {
const available = inv.isSlotAvailable(prefix);
// render slot UI using prefix (binding name) and slot (RezSlot object with name, accepts, etc.)
}
# static isBlockedByExclusion(slotBinding) → {boolean}
Parameters:
| Name | Type | Description |
|---|---|---|
slotBinding |
string
|
true if an occupied slot excludes this slot, or this slot excludes an occupied slot
boolean
# static isOverweight() → {boolean}
true if the inventory's total weight exceeds max_weight
boolean
# static isSlotAvailable(slotBinding) → {boolean}
Useful for greying out slot categories in inventory UI.
Parameters:
| Name | Type | Description |
|---|---|---|
slotBinding |
string
|
the binding prefix identifying the slot position |
true if the slot is not blocked by any exclusion rule
boolean
# static isSlotEnabled(slotBinding) → {boolean}
Slots default to enabled. Use initial_{prefix}_enabled: false in the
inventory definition to start a slot disabled, then call enableSlot() at runtime
when the player unlocks it (e.g. on reaching a required level).
Parameters:
| Name | Type | Description |
|---|---|---|
slotBinding |
string
|
the binding prefix identifying the slot position |
true if the slot has been enabled
boolean
Examples
Define a locked slot in Rez
// @inventory player_equip {
// slots: [ring1: #s_ring, ring2: #s_ring]
// initial_ring2_enabled: false
// }
Unlock at runtime
if(player.level >= 5) {
$("player_equip").enableSlot("ring2");
}
Check in UI
for(const {prefix, slot} of inv.getSlots()) {
const enabled = inv.isSlotEnabled(prefix);
const available = inv.isSlotAvailable(prefix);
// enabled=false → locked; available=false → excluded by another equipped item
}
# static itemFitsInSlot(slotBinding, itemId) → {boolean}
If the slot has has_capacity: true, items count towards
slot.capacity using their size attribute, defaulting to 1 if unset.
This means capacity: 1 naturally limits a slot to a single item unless
an item explicitly opts out with size: 0 (e.g. a weightless item) or
takes up more room with size: 2+. Slots without has_capacity: true
accept any number of items.
Parameters:
| Name | Type | Description |
|---|---|---|
slotBinding |
string
|
|
itemId |
string
|
true if the item will fit with any other contents of the slot
boolean
# static itemFitsWeight(itemId) → {boolean}
Parameters:
| Name | Type | Description |
|---|---|---|
itemId |
string
|
true if adding this item would not exceed max_weight
boolean
# static maxWeight() → {number}
the max_weight attribute, or Infinity if not set
number
# static remainingWeight() → {number}
how much more weight this inventory can carry before reaching max_weight
number
# static removeEffects(slotBinding, itemId)
Parameters:
| Name | Type | Description |
|---|---|---|
slotBinding |
string
|
|
itemId |
string
|
# static removeItemFromSlot(slotBinding, itemId) → {RezDecision}
removes the specified item from the specified inventory slot
Parameters:
| Name | Type | Description |
|---|---|---|
slotBinding |
string
|
|
itemId |
string
|
the decision from canRemoveItemFromSlot; when it is yes
the item has been removed (firing remove events and releasing effects), otherwise
the slot is unchanged and the decision carries the reason. An item that isn't in
the slot yields a no decision (failed_on: "missing") rather than throwing.
# static resolveOwner()
If owner_id was not authored directly, find the actor that
declares this inventory as its container_id and record it as owner_id,
so that inventory.owner is reliably available (for the actor veto, effect
application, and insert/remove event handlers). Author ownership in a single
place (actor.container_id); an explicitly authored owner_id still wins.
Safe at init time because all game objects are registered before any object
is initialised.
# static setItemForSlot(slotBinding, itemId) → {Array.<RezDecision>}
replaces any existing item content for the slot with this item
Parameters:
| Name | Type | Description |
|---|---|---|
slotBinding |
string
|
|
itemId |
string
|
a decision for the added item (see setItemsForSlot)
Array.<RezDecision>
# static setItemsForSlot(slotBinding, items) → {Array.<RezDecision>}
Replaces any existing item content for the slot with these items. Existing occupants are removed first (firing remove events and releasing their effects), then each new item is added through the validated path, so an item the slot can't accept is refused (and reflected in its decision) rather than silently set.
Parameters:
| Name | Type | Description |
|---|---|---|
slotBinding |
string
|
|
items |
array
|
array of item ids |
a decision for each item added, in order
Array.<RezDecision>
# static setSlot(slotBinding, itemIds) → {Array.<RezDecision>}
Replaces the slot's contents with the given items. Existing occupants are removed (firing remove events and releasing their effects) and each new item is added through the validated path. Alias for setItemsForSlot.
Parameters:
| Name | Type | Description |
|---|---|---|
slotBinding |
string
|
|
itemIds |
array
|
array of item id's |
a decision for each item added (see setItemsForSlot)
Array.<RezDecision>
# static shouldApplyEffects(slotBinding) → {boolean}
Parameters:
| Name | Type | Description |
|---|---|---|
slotBinding |
string
|
whether effects should be applied for this slot
boolean
# static slotAcceptsItem(slotBinding, itemId) → {boolean}
Parameters:
| Name | Type | Description |
|---|---|---|
slotBinding |
string
|
|
itemId |
string
|
true if the given item has a type that this slot accepts
boolean
# static slotContainsItem(slotBinding, itemId) → {boolean}
Parameters:
| Name | Type | Description |
|---|---|---|
slotBinding |
string
|
|
itemId |
string
|
true if the item_id is in the slot
boolean
# static slotIsOccupied(slotBinding) → {boolean}
Parameters:
| Name | Type | Description |
|---|---|---|
slotBinding |
string
|
true if there is at least one item in the slot
boolean
# static totalWeight() → {number}
sum of the weight attribute of every item in every slot
number