Reverse for each loop to remove = index from array?

I am building a dynamic and procedural road tool using hisms and sockets on the meshes. I use an array of the sockets’s transforms to tell the bp where/how to spawn the next road piece.

My problem is once a socket is “used” I want to clear it’s transform from the array. I am saving the index of the sockets when used and then reverse for each looping through the array and deleting the transform at the index that = the saved one.

For some reason it will absolutely not work and I can tell because my intersections are all getting placed incorrectly as a result. And I can’t do anything before play as this is completely random and procedural.

Does anyone know how to remove a transform index from an array if it is already “used”, surely my setup should work but the print string and my eyes are telling me it is in fact not working but I don’t know why.

Any help appreciatted.

I can’t see anything in particular, but I think every now and then your code is going to exit early because the random process can choose the same point twice.

A much easier way is

Using the shuffle to just get a random point seems very eloquent. Is there some sort of way to get a “predictable random” out of it? I’m wanting to continue using streams if possible.

I think the only way to do that would be to get your random integers, and then re-order the array. Just as bad in the long run :slight_smile:

I think I’ve done it! Wouldn’t of thought of it without seeing your function, so, thanks!

Yes, that looks better. You can cut it down a bit more using the LASTINDEX node too :wink: