Question: Array without sorting original

If I don’t use the “Set Variable” will the Sorted array not actually sort it but rearrange it just for the particular value. This is kind of confusing but I’m asking if you use the sorted array value, will it actually sort the array permanently or just for your value. This is the code I have…

Teleport(Event Player, Sorted Array(Global.A, Distance Between(Event Player, Position Of(Current Array Element)))[0])

The teleport to closest function does work, I’m just wondering if it globally just sorts the array so that’s the new order of it universally. Thanks! Have a fantastic day!:grinning:

From what i know Sort Array by Current Array Element sort or rearrange the Array you referencing from lower Rank to the next higher Rank by Value, the lowest Rank Value will be rearranged at index 0 (First Index or entry) and the highest of the Values at the end. As long you don’t assign the Sorted Array to a variable and store it the result Array won’t be globally permamentally handled as Sorted Array(same for Filtered Array ) you will just referencing a Value of it in your Teleprt action with Current Array element, no reflection / changes goes back to the originally Array you Sorted. Correct me if i’am wrong. Since Sorted Array will return a reference Array your Teleport attempt won’t work since the teleport location accept only single values in that case a single Vector as input, with that knowing Closest to Player will likely also not work since it also can return an Array at least with one Element. So to fix this you either need to use First of Value of Sorted Array to get the lowest or closest target or Last of Value of Sorted Array to get the most farest target.

3 Likes

Yeah, in my code all of the values in the array are vectors, and they end up ordering respective to their distance based the sorted array orientation. But yeah, it seems like it’s working really well. Thanks for the help; I really appreciate it!:grinning:

No problem glad i could help, and remember if you wanna keep a copy of your desired Array Sorted assign it to a Variable so you have the original and the sorted one you can use for later things if needed^^.

3 Likes

Just to sum it up: Sorted Array copies an array, sorts the copy and then returns the copy. It does not sort the array in place.