How do I check for multiple of the same item in my Inventory array, then remove them?

Hello,

Right now, I have a working crafting system, so long as it’s just one of each item I need to check for and remove. But I can’t figure out how to get reference to two or more of the same item in my inventory, then remove them.

Thanks.

Just run the function/code again for the second item of the same thing. “Find” node will get the first available copy each time.

Hi,

Sorry for the late reply. I’ve got it to work by doing what you suggest, but I have a final problem.

If I had 3 of the same item in my inventory, it correctly removes 2 items, then adds the crafted item. But if I click the button again, it’ll remove the 1 item remaining. So I can’t figure out how to have something like a branch that basically says “onclicked only progress if inventory has 2 or more of the item”.

Thanks for your help.

Here, this should work for that situation.

Hmm, I must be missing something from your “crafting” setup. This shouldn’t give you MORE items, it removes them from the inventory to a temporary array in case the player doesn’t have sufficient resources you wouldn’t want them to lose what they started to craft with. Post some more screen shots of how the inventory crafting system works and I may be able to help you figure it out.

So I tested this out by actually putting things into an array, I did find one issue, I forgot to “clear” the temp array when it returns the items to the main inventory. So off the “false” branch once the “For Each Loop” finishes drag off the “completed pin” and use a “Clear” node and hook the temp array up to that. You were correct it allowed you to keep your items from the temp array while returning them to the inventory. This solves that issue. I am not sure what the other issue you are having is though? I was unable to craft things if I didn’t have the necessary resources. So if I requested an item not in my inventory array it returns the temp array to the inventory and clears it out so the player must start over. That logic was working fine for me. Re-reading the original post you may not be properly switching items to select for with the “on clicked” event. But either way this system should prevent you from losing the item. It would just add to the temp array and then when you failed to craft return it to you. So not sure about your “on clicked” event removing the 3rd item.

Hi, thanks again for your help.

I tried out your suggesting, but with the temp array, it just made it possible to item dupe and didn’t produce results different from last time. I’ll just leave it as it is atm and figure it out when I get to the bug fixing stage.

Thanks again for taking the time to help.