Hi,
I have (again) a problem with arrays. :o
This time its about sorting an array.
Since there is no sorting functionality for arrays, it needs to be implemented in the graph. Also, since arrays dont have a “swap elements” function, that has to be done in BP.
As Im only sorting arrays rather small in size, the good old bubble sort will suffice.
But it doesnt work
Here is what I did:
This is the array, the Skills. This function just returns a data structure with some random values:
This is how the whole thing is called from the event graph. just putting some text out with the contents of the array (that should be sorted).
During gameplay, this is what I get:
So, obviously not only doesnt get the data sorted, but also the data gets messed up. All of a sudden there are 3 Combat, or 2 support skills there.
The GetBestFit function is suppoesed to handle the bubble sort… First some initial values are stored local (as Zack Parrish would :D)
It should be noted that the Skills input is passed as reference.
Then, I loop through the array until, at the end of the loop, the IsSorted value (which is intialized to true right before the loop) stayed true after the loop completes.
Well, its bubble sort, you know…
The loop itself looks like this:
I get some index values and the corresponding data elements. Then I compare the skill value.
The sorting should be in descending order, so in case The current element skill value is greater than the next element skill value, we do nothing, those two are already sorted.
Else, the items get swapped and sorted is set to false, which will cause the loop to be repeated util no swap was necessary, which means the array is sorted.
Alas, arrays dont have a swap function, here its is:
Pretty straight forward. I get the elements and set one for another.
It should be noted that, again, the function data input is passed as reference.
But, as you can see from the log, it just doesnt work
Is there something wrong with my graph logic
Am I assigning something wrong somewhere
Sorting doesnt work, thats one thing, but why does my data gets messed up
Any help is greatly appreciated
Cheers,
Klaus