Hello. This might be unexpected bug, or possible something that can be enchanced.
Major problem: sorted list loses its index.
Take a look at this skript
command /listTest:
trigger:
delete {testList::*}
set {testList::a} to 3
set {testList::b} to 2
set {testList::c} to 1
set {testList::*} to sorted {testList::*}
loop {testList::*}:
message "%loop-index%, %loop-value%"
The output of this will be
1, 1
2, 2
3, 3
rather than
c, 1
b, 2
a, 3
Because sorted function will automatically change index to 1.2...
Keeping index can be very meaningful when it comes to ranking.
Let's say those a,b,c are players, and list contains some score of player. We want to make ranking based on the score. However, when list is sorted, all index will be lost, and we do not know whose value is belonged to. In order to achieve ranking, I had to make a very long and inefficient skript to make ranking, but it might be really nice and handy if sorted function can still store index. If it does, all problems will be easily solved.
Lists are sorted by indexes. Currently, the output if we kept the same indexes in the sorted expression would be
a, 3
b, 2
c, 1
Sadly, Skript doesn't allow to return a list with indexes in an expression. What could be done is making it so indexes don't get sorted automatically.
Here is a way around for it anyways:
set {_sortedList::*} to sorted {_yourList::*}
loop {_yourList::*}:
add 1 to {_count}
set {_indexes::%loop-value%} to loop-index
if mod({_count}, 20) = 0:
wait 1 tick
loop {_sortedList::*}:
set {_current} to {_indexes::%loop-value%}
broadcast "%{_current}% - %loop-value%"
the problem will be when someone has the same value as other, it would be replaced
Thanks, Ayase-san.
I would reformat the list so the data value contains both your index and data value to sort,
so if your storing a score for a player set your variable like:
set {score::%player%} to "%{_gamescore}% %playername%"
then when the list is sorted the score will sort in order before the alphanumerics etc, no data can be lost/replaced by repeated data values. The only issue might be that the {_gamescore} might require the number to be formatted like "00054" rather than "54" so that it properly sorts along with numbers of higher or lower digit counts.
Then once the list is sorted with the data setup like this you can recover both your sorted values by parsing your value as
set {_score::*} to loop-value parsed as "%number% %player%"
Duplicate of #202. I will post @Ayase-san's solution there though for anyone looking.
Most helpful comment
Lists are sorted by indexes. Currently, the output if we kept the same indexes in the sorted expression would be
Sadly, Skript doesn't allow to return a list with indexes in an expression. What could be done is making it so indexes don't get sorted automatically.