Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.

My Question:

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

Product Version: Not Selected
more ▼

asked Jul 15 '14 at 01:06 AM in Blueprint Scripting

avatar image

146 32 48 54

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Jul 15 '14 at 03:29 AM

avatar image

3.4k 154 51 271

avatar image DreamBotStudios Jul 15 '14 at 07:38 PM

Thanks mindfane for feedback...

The +1 was placed on variable [CurrentStackCount] on a Parent Item Blueprint. It is separate from the inventory array.

What your recommending is having 2 arrays, one for Inventory Items(which I have). Then an Array for Items in each slot?

I currently am using Parent Blueprints for the Pickup Item. This Parent item has its own "CurrentStackCount" int. So I just +1 every time I find a match.

I can find the match, but having issues with checking the rest of the array. Curious if I loop thru whole array to find matching then somehow save this data in variable... or once find matched item, +1 the stack count. Then find if matched on other locations of array, if matched delete that item.

avatar image mindfane Jul 16 '14 at 03:06 AM

I am still clear about your logic here. So I am speculating. However if you could show me the blueprint, I ight be able to help.

Anyway, Let us see if I got it correctly.

Your Inventory array contains several objects. All these objects has a Parent Item meber whcih is anotehr blueprint. You want to loop though the items and when you find a match, you want to increment a counter on the Parent Item of the matched inventory item. Did I get it right?

Also I would like to know if your inventory item array will contain duplicate instances of the same item? If not, you can immeidtaley break once you find a match and update the counter. Ottherwise you need to set a boolan vairable to indicate if a match has been found nor not and continue with the rest of the array. Delete any duplciate entries if the boolean flag is set.

..still I am assuming too much. If its possible, try to uplaod an image of the two blueprints in question.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question