For each loop inside a for loop missing a value

Hi there, this is my first time posting so i’m not sure the best way to ask this question :slight_smile:

In the script below i have a for each inside a for loop and based on comparing values i’m sorting both into an array with an additional variable.

However, for some reason one of the values in the for each loop appears to be getting completely ignored and as far as i can tell it definitely shouldn’t be.

I am probably missing something incredibly simple, but for the life of me i just can’t see it.

Any help or thoughts/better ways to approach this, would be greatly appreciated,

Thank you.

Ha, thanks, yeah, the break was actually left over from the the other add, don’t know why it’s there :slight_smile:

I’ve tried putting a string and the values should be correctly sorted but it is somehow missing one and not getting added. With debug it shows that the # of the for each never drops below 2 either. I’ve thoroughly confused myself.

Thanks for the help.

Okay, well have you tried putting a print string on the branch false condition? I have a feeling that one of the values is equal or greater and causing the branch to take the false route, giving you one less in your array. That is the only thing I can see that could possible be happening.

Also the for each loop with break can simply be a normal for each loop because your on completed is adding to the array then going back to break essentially nothing. Break is there to stop the loop anytime during its looping (so if a condition is met, you can stop the loop and prevent unnecessary looping), once its completed there is nothing to break.

No problem. So if you put a print string node on the false branch, then run this code, does anything print to the screen?

Could I see what you have connected to your first for loop? and what exactly is it you are trying to do?

Would this work? I apologize if im not fully understanding the issue. Also instead of a 2D vector you could probably use a map with a float and bool (only if your positive there will never be two distances that are the same.)

Oh, yeah… sorry, it does however, that means it is needs to be the other add and so i let false go nowhere… as when i’ve tried putting it to the other add i end up with duplicate entries (even with add unique) because of the second variable

— EDIT —
okay, so you gave me an idea so added another branch on the false that check to see if the value was less than the next index of the for loop (not the for each) and then if that is true i add it and it comes out correct! :slight_smile: - though, it still isn’t perfect, cause it gets the first 2 wrong so i need a way to fix that :wink:

— EDIT #2
yeah, that doesn’t work :slight_smile:

Basically, i’m trying to store begin and end points for a spline mesh based on other static meshes along the spline that have been placed previously. so i need to know when a static mesh is there and when it isn’t so i know how to treat the value and leave a gap. the best way i could think of doing that was with a 2D vector cause i can store a second variable that acts as a bool.

I have a num points on spline attached to the for loop - see below

Hi there, thanks, i’ve never used a map before, i’ll look into it, could be the way to go.
With the setup you have added (thanks for that) the spline isn’t in a for loop would it still need to be? i assume so otherwise you’re always getting the same index.

Also, when i’ve tried to do something similar i end up with duplicate values in the array somehow.

I’ll give it a shot, thanks again.

so, in your example you’re removing the index whether it is true or not and i can’t do that, it has to be remain until it is less as it always should be less than a distance along the spline, but just not at that point perhaps.

the branch is for seeing if the stored float array # value is less than the current spline index’s distance value, if it is, then that is a static mesh and should be placed in the array with the addition value of 1. Otherwise it should be added to other with a 0.

So i tried setting it up exactly as you have it (though with an add unique for the second add array) and it is still confusing me, somehow they still get inserted out of order which makes no sense to me…

This is a shot with the values shown…

I think i just figured it out!!! :slight_smile:

I need to restart the for each loop each time it is true otherwise i’m missing subsequent lower values that may come after the current one in that array… i think it’s working!! :slight_smile:

Thank you very much for your help getting me there!! :smiley:

If im not understand correctly, what is the branch check for? What does it mean if its true, and what does it mean if its false?

Ah yes, okay that makes sense. I’m glad you got it figured out! :slight_smile: