How To Go Through All Items In Array? For Loop or For Each?
I have an Inventory Array which I wish to go thru all the items in this array. I have most of the functionality working except going thru array to check items, so I can setup stacking the inventory by adding +1 to the item (to track how many items I have in the slot).
When I click on item in game world, I would like to to check: If the clicked items match the class, then add +1 to that class of item. If the clicked item does not match, then go to the next item and do check if item matches class again.
What happens is I add the item to the array, but it does not stack the items. Instead it adds both items.
If I use a Loop, do I need to remove the previous item in the loop that matches the item? Or is there a way to do a check on all items in the loop, then if one matches... do the +1 to stack the inventory item.
Thanks in advance... Markus
asked Jul 15 '14 at 01:06 AM in Blueprint Scripting
Foreach loop might work in this case, I think.
One question though, you said you are adding +1 when you find a match. Exactly where do you intend to perform this increment operation? Is it a separate array of 'Int's? You can use the Index pin to sync the two arrays. Anway when you've found your matching item, you can do the logic you need (adding +1 in this case) and feed back to the 'Break' pin of for-ach node. This will make sure that once a match is found, looping is stopped immeditaley.
If you can post a pic of your blueprint, I might be able to help more.
Follow this question
Once you sign in you will be able to subscribe for any updates here