Using an Array to create a highest to lowest list.

ZelsesWind

Villager
Member
Joined
Mar 15, 2014
Messages
15
Reaction score
0
First Language
Spanish
Primarily Uses
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.
 

waynee95

Inactive
Veteran
Joined
Jul 2, 2016
Messages
682
Reaction score
598
First Language
German
Primarily Uses
RMMV
@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++;
});
 
Last edited:

ZelsesWind

Villager
Member
Joined
Mar 15, 2014
Messages
15
Reaction score
0
First Language
Spanish
Primarily Uses
@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.
 

waynee95

Inactive
Veteran
Joined
Jul 2, 2016
Messages
682
Reaction score
598
First Language
German
Primarily Uses
RMMV
What do you wana do exactly?

EDIT: Take a bunch of variables and sort them?
 
Last edited:

ZelsesWind

Villager
Member
Joined
Mar 15, 2014
Messages
15
Reaction score
0
First Language
Spanish
Primarily Uses
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.
 
Last edited:

waynee95

Inactive
Veteran
Joined
Jul 2, 2016
Messages
682
Reaction score
598
First Language
German
Primarily Uses
RMMV
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.
 

ZelsesWind

Villager
Member
Joined
Mar 15, 2014
Messages
15
Reaction score
0
First Language
Spanish
Primarily Uses
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.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,862
Messages
1,017,045
Members
137,569
Latest member
Shtelsky
Top