Using an Array to create a highest to lowest list.

Discussion in 'RPG Maker MV' started by ZelsesWind, Sep 1, 2017.

    Tags:
  1. ZelsesWind

    ZelsesWind Villager Member

    Messages:
    15
    Likes Received:
    0
    Location:
    México
    First Language:
    Spanish
    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.
     
    #1
  2. waynee95

    waynee95 Lunatic Coder Veteran

    Messages:
    616
    Likes Received:
    500
    Location:
    Germany
    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 (ab) {
            return 
    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(idvalue);
        
    id++;
    });
     
    Last edited: Sep 1, 2017
    #2
    Tricimir and ZelsesWind like this.
  3. ZelsesWind

    ZelsesWind Villager Member

    Messages:
    15
    Likes Received:
    0
    Location:
    México
    First Language:
    Spanish
    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.
     
    #3
  4. waynee95

    waynee95 Lunatic Coder Veteran

    Messages:
    616
    Likes Received:
    500
    Location:
    Germany
    First Language:
    German
    Primarily Uses:
    RMMV
    What do you wana do exactly?

    EDIT: Take a bunch of variables and sort them?
     
    Last edited: Sep 1, 2017
    #4
  5. ZelsesWind

    ZelsesWind Villager Member

    Messages:
    15
    Likes Received:
    0
    Location:
    México
    First Language:
    Spanish
    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: Sep 1, 2017
    #5
  6. waynee95

    waynee95 Lunatic Coder Veteran

    Messages:
    616
    Likes Received:
    500
    Location:
    Germany
    First Language:
    German
    Primarily Uses:
    RMMV
    PHP:
    // Create emtpy array
    var numbers = [];
    // Iterate over game variables and store them in array
    for (var start<= endi++) {
        
    numbers.push($gameVariables.value(i));
    }
    // Sort array
    numbers numbers.sort(function(a,b) { return a; });
    Make sure to replace start and end with the actual ids.
     
    #6
    Tricimir and ZelsesWind like this.
  7. ZelsesWind

    ZelsesWind Villager Member

    Messages:
    15
    Likes Received:
    0
    Location:
    México
    First Language:
    Spanish
    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.
     
    #7

Share This Page