Use for each loop to count amount of times a string appears in an array?
I am currently trying to make an "store" full of items which give the player different stats. such as health etc. I have done this by making the blueprints pull their stats based off if an item is in their "Inventory" array. The problem is if they get the same item twice. I would like to be able to count the amount of times and item is in their inventory so I can give them the stats required. Such as if you get for example - 2 10hp items with the same name it counts them separatley as right now I have it with a true false branch with the Boolean being a "contains" within an array.
asked Nov 29 '18 at 03:29 PM in Using UE4
Just create a counter variable, set it to 0 in the beginning, go through the Inventory with a ForEachLoop, and if Item == "Skean", then increase this variable by 1. After completing, you'll have the number of times the item occur in your array.
answered Nov 29 '18 at 04:18 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here