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"

Count number of true booleans in array

Hi everyone,

Is there a way that you can count the number of true variables in an array of booleans? I want to have an updating int variable that returns 0 if all false, 1 if 1 true, 4 if 4 true etc. Is this possible with blueprints? I've tried a ForEachLoop node and a length node but those don't allow you to actually test the variables in the array, just simply get all of them.

Thanks for your help!

Product Version: UE 4.15
Tags:
more ▼

asked Apr 17 '17 at 09:51 PM in Blueprint Scripting

avatar image

ollyryder
3 2 3 5

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

3 answers: sort voted first

you could try something like thisalt text

where the for each loop gets the value of the array at every index (1 the first pass, 2 the second, so on...) then this converts the bool into integer where 1 = true and 0 = false and if the value is equal to 1 then it adds up the count of true bools.

answer.jpg (74.2 kB)
more ▼

answered Apr 17 '17 at 11:00 PM

avatar image

sudoadmin
37 2 3 7

avatar image sudoadmin Apr 17 '17 at 11:03 PM

Another way that doesn't involve conversion to integer so it'll be more intuitive is thisalt text

answer2.jpg (73.3 kB)
avatar image ollyryder Apr 18 '17 at 12:35 AM

Ah thank you very much, that does the trick! I didn't know you could use the get node to compare more than one with foreachloop.

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

alt text

_7.png (77.4 kB)
more ▼

answered Apr 17 '17 at 10:48 PM

avatar image

vanlacke
1.5k 65 132 103

avatar image sudoadmin Apr 17 '17 at 11:06 PM

he was looking for a bool array not an integer array... thanks for the logic portion though my initial attempt was messy I was unaware of the existence of the branch node

avatar image vanlacke Apr 17 '17 at 11:28 PM

It was worded weirdly. He can easily replace the IntArray with a bool array and it would work exactly the same.

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

Why not just use the array element in the branch?

more ▼

answered Apr 18 '17 at 12:12 AM

avatar image

Radiance37k
61 2 3 7

avatar image sudoadmin Apr 18 '17 at 07:29 PM

thatd work fine too

(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