For each loop skips last index

Hi there,
I’ve got a parametric fuse box. I check the fuses sequence by comparing the state of each fuse and the target states.
However with my setup the last fuse (last array index) keeps being skipped by the for each loop. I’ve got 16 fuses, but only 15 states at the end of the for each loop.

Any idea where I am wrong ?

Well here is a screenshot of my construction script. When using another bool array the for each loop takes all indexes, there probably is a mess with the creation of my “Fusible Status” bool array.
Aaaaaand I know I should never modify an array while a for each loop is looping using this array, but can’t find how to do this differently… The check code function is only called after the creation of the array btw.

Aaaaaand I know I should never modify
an array while a for each loop is
looping using this array, but can’t
find how to do this differently…

You can use a reverse foreach loop and that way if you want to remove an element from that array it won’t interfere with the rest of the loop.

I’m not sure about that missing index 15 though.

Ok now it works well. I had to replace the “Fusible Status” Array with a Fuse references array in the construction script.
Then in event graph, when “Check Code” function is called, for each Fuse reference, the “On?” variable is added to “Fusible Status” Array.
This way the “Fusible Status” array is dynamically updated each time a Fuse is modified in-game (fuses call the “Check Code” function when their status is changed).

Reversing the array makes a mess with the check thing. How could it check one array in one way with another in reverse ? This would be a mess with index int operations. I finally found a solution, see below. Thanks for the suggestion though !

The index output from the loop is in reverse too, so any other associated array you use that index for will still be correct. Glad you found a solution!