Using an Array to create a highest to lowest list.

Hello everyone.

I want to make the game check the Strenght of all the characters and sort it from highest to lowest and make a queue list, so the characters will take action according to their possition in the queue.

I guess this is exactly the same as who strikes first in each battle turn, but I want this for a different purpose out of battle scene.

I was thinking of using Script call and Arrays, but I wouldn't know how to make the game send the variables already sorted. I thought maybe using conditional branches to check 3 to 18 variables combined would factor up pretty fast, but maybe I'm using the wrong approachment.

Would you help me please with any method you could think of? I understand common eventing a bit better, but script calls not so well.

Thank you.
@ZelsesWind
This would require the use of some JavaScript.

PHP:
// 1. Iterate over all party members and get their atk value. 2. Sort that list from highest to lowest
var list = $gameParty.members().map(function (actor) {
        return actor.atk;
    }).sort(function (a, b) {
        return b - a;
    });
// Iterate over the sorted list and store the values in game variable 3 to length of the list
var id = 3;
list.forEach(function(value) {
    $gameVariables.setValue(id, value);
    id++;
});
@ZelsesWind
This would require the use of some JavaScript.

PHP:
// 1. Iterate over all party members and get their atk value. 2. Sort that list from highest to lowest
var list = $gameParty.members().map(function (actor) {
        return actor.atk;
    }).sort(function (a, b) {
        return b - a;
    });
// Iterate over the sorted list and store the values in game variable 3 to length of the list
var id = 3;
list.forEach(function(value) {
    $gameVariables.setValue(id, value);
    id++;
});

Thank you very much @waynee95, it works very well.

Could I bother you with something else about this, please? I'd also like to use this script call with variables I make, instead of character attributes. I tried to use $gameVariables.value(1), $gameVariables.value(2) instead of $gamepartymembers, but I'm unable to figure out the syntax.
What do you wana do exactly?

EDIT: Take a bunch of variables and sort them?
Exactly what you wrote above in the script call, but this time, instead of sorting character's Atks in the list of variables, I'd like to sort some variables I made in Control Variables. Did that make sense, or should I attempt to explain it in another way?

EDIT: Hold up, let me gather my thoughts, I'm getting a bit confused about what I am trying to achieve.
PHP:
// Create emtpy array
var numbers = [];
// Iterate over game variables and store them in array
for (var i = start; i <= end; i++) {
    numbers.push($gameVariables.value(i));
}
// Sort array
numbers = numbers.sort(function(a,b) { return b - a; });
Make sure to replace start and end with the actual ids.
PHP:
// Create emtpy array
var numbers = [];
// Iterate over game variables and store them in array
for (var i = start; i <= end; i++) {
    numbers.push($gameVariables.value(i));
}
// Sort array
numbers = numbers.sort(function(a,b) { return b - a; });
Make sure to replace start and end with the actual ids.

Yes, this is it, it works just like I needed it. Thank you kindly @waynee95 , for your time and help.

This can be closed now.

Original thread: https://forums.rpgmakerweb.com/threads/using-an-array-to-create-a-highest-to-lowest-list.83472/