How do you lookup a specific value in a Struct in an array

My inventory consists of a struct array inside of a scroll box. The struct has an image, a description, and a quantity associates with it. I am trying to make it not add an item in a new inventory slot if it is already in my inventory, instead it will just add to the quantity. The inventory struct is “InventoryButtonStruct2” and the info from the item i am picking up is added through the “AddInventory” event.

This is the original code for adding the item to the array.

I then broke down the incoming information to see if one of the entries contained the same description as the one I was wanting to add. I collapsed the Image and the quantity on the make/break struct nodes to run this check hoping it would not look at them but that was not the case. This of coarse did now work because the all 3 things in the entry had to match the one you wanted to add before it said it contained it already

It all leads down to How do I search the struct for just “InventoryButtonText” string? In addition to that I need to add the quantities of the items together if the item already exists in my inventory if anyone can help with that.


not sure if it’s the most efficient way to do this, but what i’ve done in the past is include an ‘id’ variable in the struct, so in the list of structs, each member has an integer variable ‘ID’. that way, i can use the ‘foreachloopwithbreak’ node and check to see if the id of the struct being checked already exists in the list and branch from there.

So what you are saying is a separate Id for each Item like 1 for shotgun 2 for shotgun ammo, 3 for water, and so on?

yeah, it works when i’ve done that in the past, but again, i don’t know if there’s a more efficient way of doing it.

As for efficiency I am not too picky, I typically find a way that works and then later if I find a better way then I can always change it.

I am having the same problem and don’t want to open a new thread for it. Did you get this ForEachLoopWithBreak solution to work?
I can’t figure out how to do it. I’d need a node-for-node description. Does it still involve a Contains node? And what on Earth do I plug into the Loop Body exec?
A simple screen shot would be best.

I added a Item ID to the Struct array for my button and did a search for it. I did get it to work after a lot of trial and error. I can post a picture for you tonight, I do not have access to my game files at this time.

Thank you, that would be great. I’ve been trying to figure this out for many days.

So the “contains” node was useless unless you have the exact match. I plug the loop body into a branch that will go true if it finds a match, in this case the Item ID from my Inventory Button Struct. My “Item Found In Inventory” goes true when it finds a match and then after if goes through the completed branch it goes false so it can be used again. This current setup adds the additional item quantity to any existing item already in the inventory. You don’t necessarily need to add an ID for the item, as long as it contains something off of the Array Element to match it will work.

Thank you, this helped me a lot with building my quest log system.

Hey your link is broken do you still have this ?