It’s just a simple blueprint version of a bubble sort and I think I replicated it exactly as he had it, but for some reason mine creates an infinite loop. The swap works fine and if I take off the boolean that flips when a swap occurs, no problems, it just does the ‘for loop’, swaps all those entries, but then leaves the rest unswapped. If I put the boolean flip to reactivate the while loop like I’m supposed to, it creates an infinite loop.
What am I doing wrong? I know this should be basic programming but I’m having a pretty hard time figuring it out.
Thanks but that didn’t help. I’m more looking for why the loop would create so many iterations when it should reach a point where the list is in order and it stops.
Yeah I’m not getting an out of bounds exception for the for loop. It’s just when the while loop gets added into the mix that it creates too many iterations. I did what you said, but the length of the array isn’t changing. Like I said it does one iteration fine but when a swap happens that should retrigger the while loop and I set it with the bool, it creates an infinite loop.
Obviously, there is an array out of bounds error in your code, your forloop range is (0, length()-1), and the ArrayGet range is (0, Array.length()), which will cause an array out of bounds exception on the last loop.
According to your error message, you did not cause an array out-of-bounds exception, but an infinite loop exception occurs, which shows that you have changed the length of the array by mistake in the swap() method. Maybe your array is growing infinitely, so the forloop is always Endless.
The test method is very simple, just print the current forloop index and array length after swap().
In addition, you should use Array.SetArrayElement() instead of add/remove which is less efficiency.
The loop method is correct and I have tested it without infinite loop error if I change the foorloop range to (0, len()-2);
Maybe you should check the GetPerfCamIDFromName method(is it returns non-change values when called multi-times) and check if the swap() successed, both of them could cause infinate loop.
Loop while is for most stuff broken(or rather doesn’t work as you’d expect). The reson you have an endless loop is that your setting the bool on the while loop that happens every frame so it will set to true every frame. I would make a loop while with delay.
To make a loop while with delay place a sequence and off of out pin 2 place a delay then a branch from there loop back to the sequence in. Your bool now goes into the branch.
But you actuly dont need it at all you if you delete the loop while and add a delay then branch to the complete of the for each loop. You can run from the branch to the set bool(done sorting) true now it’ll only complete once or will loop slowly forever if the swap never happens.