I think something like that should work, this goes to your InventoryData
class script.
func remove_item(item_data: ItemData, quantity: int) -> bool:
var counter: int = -1
for slot_data in slot_datas:
counter += 1
if slot_data == null:
continue
elif slot_data.item_data != item_data:
continue
elif slot_data.quantity < quantity:
continue
elif slot_data.quantity == quantity:
slot_datas[counter] = null
print("SlotData removed")
return true
else:
slot_data.quantity -= quantity
print("SlotData quantity updated")
return true
print("No item of this type found")
return false
Not sure though if you are allowed to remove the SlotData
from the slot_datas
array, so in case anything breaks with this code - let me know.