Skip to content

YaBackpackComponent

Beta
YaBackpackComponent manages the backpack and items to be put in or moved out of the backpack.

Functions

YaBackpackStacks[] GetAll()Beta
Gets the information of all the items in the backpack.
number GetCapacity()Beta
Gets the capacity of the backpack.
number GetCount(number itemID)Beta
Returns the total number of the items in the backpack by itemId.
number Addable(number itemID, number count)Beta
Whether the item could be add to the backpack.
  • itemID itemId
  • count add count
void Sort()Beta
Sort the backpack.
void Clear()Beta
Clear the backpack.
boolean Replace(number fromIndex, number toIndex)Beta
Exchange the position of the two item in backpack.
  • fromIndex from
  • toIndex to
void Add(number itemID, number count)Beta
Add item to backpack.
  • itemID itemId
  • count count
void Add(number itemID, number entityId, number count)BetaDeprecated
Obsoleted,use Add(int itemID, int count) instead.
  • itemID itemId
  • entityId item's entityId
  • count item count
void Remove(number index, number count)Beta
Remove an item from backpack.
  • index the index in backpack
  • count count
void RemoveByItemId(number itemID, number count, number fromIndex)Beta
Remove item from backpack by itemId.
  • itemID itemId
  • count count
  • fromIndex start position in backpack
void Enable()Beta
Enable backpack.
void Disable()Beta
Disable backpack.

Events

ChangedEvent<void>Beta
Fired when the backpack's data changed.
ItemAddedEvent<BackpackItemChange>Beta
Fired when an item is added.
ItemRemovedEvent<BackpackItemChange>Beta
Fired when an item is removed.

Code sample

Code sample

-- Prepare the component.
local backpack = script:GetYaComponent("YaBackpackComponent")
-- Get all the items in the backpack.
local items = backpack:GetAll()
-- Check if the item is addable with itemId and count. If 0 is returned, you cannot add the item anymore.
local count = backpack:Addable(itemId, countToAdd)
-- Put 10 items to the backpack.
backpack:Add(itemId, 10)
-- Remove an item from the backpack of ```counttoRemove```. ```fromIndex``` is the index position of the item in the backpack.
backpack:Remove(fromIndex, countToRemove)
-- Remove all items from the backpack.
backpack:Clear()