Hi all. I’m looking for some help on the best way to do this. I am trying to learn how to best use for loops and avoid making staircases of branches. I have a working version of this through branches but I don’t believe it is the most optimal way to code this.
Essentially, I want to make an array that is checked. The event checks "is EVERY value in this array greater than the value of 0? If true, run the rest of the script.
Currently, the array is checked one-by-one. If one value is greater than 0, it passes through and says “yes, this singular item in the array is greater than 0”. I need it to only be when ALL are greater than 0. How can I do this?
Thank you, I wasn’t too sure about that bit regarding array index!
I’ve tried this set-up and “true” seems to pass as long as just one item is greater than 0. There are 6 items so it triggers “WI, loss loss, loss, loss…” if one item is greater.
Am I doing something wrong? I also promoted the array > 0 to a variable like in the screenshot.
In @Everynone 's answer, they were NOT setting a variable, they were returning from the function call. The return from the function call would short-circuit the loop to stop it from executing once you’ve found a false value.
Essentially the “Element” must be higher than 0, if that is not true then the loop breaks(ends) and it cannot reach the next “thing” in the array.
Therefore if the index value hits 6 (The number of variables in my array), then it must mean they all have a value. This is the solution that seems to work best for my situation with arrays, however you could also do this with an “isTrue” boolean by replacing the array element <= 0 with an “isTrue” boolean.
(For my situation, the extra blank (6) was neccessary)
This is actually still not a good solution, and does not need fakery to fool the conditions into working, and you absolutely should NOT need to check the array index.