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"

Is it possible to use the Array "Contains" with a single conditional?

I wanted to know if a specific integer array contains any value other than 0.

By default all items of the array in question are 0. During gameplay any of them could go up to 1 ~ 999.

Would it be possible to stick something special into Contains' "item to check for" to have it return true only if something other than 0 is found?

Right now I'm doing this check using a foreachloop. But it seems kinda taxing for such a simple thing.

Product Version: UE 4.12
more ▼

asked Oct 21 '16 at 08:40 AM in Blueprint Scripting

avatar image

352 34 34 53

(comments are locked)
10|2000 characters needed characters left

3 answers: sort voted first

Hey kusokuso1-

If you have your get array node selected and drag out from there you can add a "Max of Int Array" node which will search the array and return back both the max of all entries in the array as well as the index the entry was found at. If the array is empty then it returns a value of 0 at index -1.

alt text


Doug Wilson

maxint.png (27.4 kB)
more ▼

answered Oct 21 '16 at 07:25 PM

avatar image kusokuso1 Oct 26 '16 at 05:21 AM

Awesome. Thanks a lot, Doug Wilson. This is much cleaner than the for loop check. Works nice!

(comments are locked)
10|2000 characters needed characters left

Rather than checking your array in a loop, implement delegates. In blueprints they are Event Dispatchers.

You would implement the dispatcher on your game element that modifies your array to fire. Then you implement your logic whenever that event dispatcher fires, this is a lot more efficient.

more ▼

answered Oct 21 '16 at 06:12 PM

avatar image

1.2k 31 8 32

avatar image kusokuso1 Oct 26 '16 at 05:34 AM

Hey thanks a lot for the help, MajinSephiroth. I apologize for not being more clear about how I had that for loop implemented. Actually, I was initially doing the for loop in an event bound to a dispatched event. I use dispatchers sparingly, but I take it I should use them more often for inter-object communication.

(comments are locked)
10|2000 characters needed characters left

I don't think there is a other solution, except you sort your array by decreasing order after you change a item.

You can write a own function so you only have one node in your BP, but I think there is no other solution than a for loop to check all elements in an array

more ▼

answered Oct 21 '16 at 10:13 AM

avatar image

525 22 10 34

avatar image kusokuso1 Oct 26 '16 at 05:44 AM

Speckulous, thanks for the help. Interesting, I've never tried to sort an array before. If I did as you specify, then I'd need only check the item of the first or last entry in the array which is cool. I will remember this. Thanks!

(comments are locked)
10|2000 characters needed characters left
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