Is there any simple way to sorting list variable's keys?

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the community!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

pepper82

Member
Jan 26, 2017
272
1
18
Hey all,
I would like to sort a list from highest to lowest key.
Here my example:

set {_a} to "Marion"
set {_b} to "Alex"
set {_c} to "Walburg"
add {_a} to {_test::*}
add {_b} to {_test::*}
add {_c} to {_test::*}
set {_test::a} to 100
set {_test::b} to 200
set {_test::c} to 300

After sorting this list the output should be:
Walburg - 300
Alex - 200
Marion - 100
 
that's not how Skript works, of course it might be possible but it'll just overcomplicate the things. If your problem is that using the index makes the name lowercase then instead of use player names use UUIDs and then convert them to names with the parse expression.
 
that's not how Skript works
What do you mean? You can't/shouldn't sort a number list on skript? I don't quite follow you there

@i998979 (on the old forums) made me a parkour times sorting algorithm based on bubble sort. I have the code right here, but if you are not familiar with sorting algorithms it will be quite freaking difficult to understand.

code_language.skript:
delete {parkour.Name.1::*}
delete {parkour.Data.1::*}
set {_size} to 1
loop {parkour.record.1::*}:
    add loop-index to {parkour.Name.1::*}
    add loop-value to {parkour.Data.1::*}
    add 1 to {_size}

loop {parkour.record.1::*}:
    set {_size3} to 1
    set {_size4} to {_size3} + 1
    loop {parkour.record.1::*}:
        if {parkour.Data.1::%{_size3}%} > {parkour.Data.1::%{_size4}%}:
            set {_temp1} to {parkour.Data.1::%{_size3}%}
            set {parkour.Data.1::%{_size3}%} to {parkour.Data.1::%{_size4}%}
            set {parkour.Data.1::%{_size4}%} to {_temp1}
          
            set {_temp1} to {parkour.Name.1::%{_size3}%}
            set {parkour.Name.1::%{_size3}%} to {parkour.Name.1::%{_size4}%}
            set {parkour.Name.1::%{_size4}%} to {_temp1}
          
        add 1 to {_size3}
        add 1 to {_size4}
      
set {_final} to 1
loop {parkour.record.1::*}:
    if {_final} is 1:
        set {_color} to "&e"
    else if {_final} is 2:
        set {_color} to "&7"
    else if {_final} is 3:
        set {_color} to "&6"
    else:
        set {_color} to "&d"
    if {parkour.Name.1::%{_final}%} is player:
        message "%{_color}%&l[%{_final}%] &9&l%{parkour.Name.1::%{_final}%}%&7&l: &b&l%{parkour.Data.1::%{_final}%}%"
        set {_gotposicion} to true
    else:
        message "%{_color}%[%{_final}%] &9%{parkour.Name.1::%{_final}%}%&7: &b%{parkour.Data.1::%{_final}%}%"
    add 1 to {_final}
    if {_final} is higher than 10:
        stop loop
message " "
if {_gotposicion} is not set:
    set {_posicion} to 1
    loop {parkour.record.1::*}:
        {parkour.Name.1::%{_posicion}%} is player:
            set {_tuposicion} to {_posicion}
            stop loop
        else:
            add 1 to {_posicion}
    if {_tuposicion} is not set:
        message "&7&l[--] &9&l%player%&7&l: &b&lNo clasificado"
    else:
        message "&7&l[%{_tuposicion}%] &9&l%player%&7&l: &b&l%{parkour.Data.1::%{_tuposicion}%}%"

No clasificado - not classified
tuposicion - yourposition
{parkour.record.%{_point}%::%player%} has the time of a single segment of my parkour. That's what gets sorted, if i remember correctly.
 
that's not how Skript works, of course it might be possible but it'll just overcomplicate the things. If your problem is that using the index makes the name lowercase then instead of use player names use UUIDs and then convert them to names with the parse expression.

Could you post an example?
And it's not only for Player Names.
 
xUndefined: You code seems long and complicated. I am looking for a "simple" function or something that I can use to quickly sort list variables from high to low and low to high.
 
xUndefined: You code seems long and complicated
Sorting in skript is long and complicated. You can always adapt my code to your needs, but the general idea that you're going to have to use something similar to bubble sort stands.
 
randomsk has a sorted expression but i think randomsk is outdated idk but anyways i came up with this
code_language.skript:
set {_rank} to 0
loop size of {unsortedList::*} times:
    add 1 to {_rank}
    set {_highestScore} to 0
    loop {unsortedList::*}:
        if loop-value-2 is greater than {_highestScore}:
            set {_highestScore} to loop-value-2
            set {_highestPlayer} to loop-index
    remove {_highestScore} from {unsortedList::*}
    set {sortedList::%{_rank}%} to "%{_highestPlayer}% - %{_highestScore}%"

#broadcasting list
loop {sortedList::*}:
    broadcast "%loop-value%"

#or to get a the player/score at a specific rank, i.e. 5
broadcast "%{sortedList::5}%"
the only problem with this is it wont handle ties very well but you or someone else can add that (or maybe i will if i get the chance)
 
Status
Not open for further replies.