x

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 detect which elements in an array have duplicates

Greetings folks! Lets say I have an array which has duplicates of some elements (This is intentional). How might I go about reporting which of those elements do occur more than once in the array?

Example: Lets say I have an array with the following strings as elements:

  • [Cat]

  • [Dog]

  • [Cat]

  • [Fish]

Then, in blueprint, I compare that array to the input [Cat], and desire an output of 'True' (or alternatively an integer of the # of occurrences would be fine too). Using the input of [Dog] should yield the output 'False' (or integer 1).

Anyone know how I could achieve this?

Product Version: Not Selected
Tags:
more ▼

asked Mar 14 '16 at 04:33 AM in Blueprint Scripting

avatar image

hypersapien
194 34 30 42

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

2 answers: sort voted first

Can´t you achive the exact thing you are asking for by a simple counter? If the counter is 1 then there are no duplicates. (false) 2 or more would imply duplicates. (true) 0 is of course not found in array. (error message?)

I guess you would want to reset counter to 0 at starting the function.

Counter solution?

counter.png (149.3 kB)
more ▼

answered Mar 14 '16 at 01:00 PM

avatar image

Stupet
81 5 8 10

avatar image hypersapien Mar 14 '16 at 08:15 PM

Thanks for your suggestion. I considered having an INT that would count upward as it found matches, but I couldn't visualize what that network would look like. I just happened to figure out the other method first so I went with that.

I've never seen that CompareInt node before, so I'll file that away for future use =) Thanks for your help.

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

Well I came up with a solution that accomplishes this, but it's messy. If anyone knows an easier way I'd love to hear it.

alt text

Arrays in this image:

  • [Potential Doorway List] Contains all of the elements I'm interested in searching, including duplicates

  • [Potential Doorways Checker] Starts out blank, then becomes a duplicate array of the previous one, except the element which is currently the focus of our loop has been removed.

  • [Positions for Door BP] the preceding branch should add any duplicate elements it finds to this array, as my final list of all duplicates found.

more ▼

answered Mar 14 '16 at 07:21 AM

avatar image

hypersapien
194 34 30 42

(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