I have an inventory, there are a few slots inside it, and inside every slot an item can be assigned. For example when i click on item, it adds correctly.
var itemslots = slots.filter(func(slot): return slot.item == item)
if !itemslots.is_empty():
pass
else:
var emptyslots = slots.filter(func(slot): return slot.item == null)
if !emptyslots.is_empty():
emptyslots[0].item = item
update.emit()
But when i want to access it i don’t know how to. I need that for multiple things (Drag and Drop system, puzzles and interactions)
Items are *.tres files, Inventory is Array, also *.tres. InvSlot is like a holder for InvItem, you assign an item to slot ant the slot to the inventory.
So my question is how to access it? Also it would be great if anyone helped me with drag’n’drop, not only to place an items, but to remove them as well. Thx!
Your post raises some questions due to a lack of information. What do you mean when you say you want to access it? From where? How is your scene layed out? The inventory can work fine with signals. You have the inventory emit signals when an item is added or removed and have it respond to signals like an item pickup.
If you want the player to interact with the inventory, you’d probably need to have the InvSlot respond to user input.
func FindIndexInvItemByName(InvItemName: String)->int:
var index:int=0
for IS:InvSlot in slots:
if IS.item.name == InvItemName:
return index
index+=1
return -1
and
func AccessChangeName (
CurrentNameOfInvItem:String,
NewName:String,
)->bool:
var index:int=FindIndexInvItemByName(CurrentNameOfInvItem)
if index==-1:
return false
slots[index].name=NewName
return true