Arctica

Veteran
Veteran
Joined
Jul 19, 2021
Messages
64
Reaction score
58
First Language
English
Primarily Uses
RMMZ
JavaScript:
Game_Action.prototype.elementsMaxRate = function(target, elements) {
    
    // attackElements() determines whether this condition runs or not, should the target have any.
    if (elements.length > 0) {
    
        // When a target is attacked, their elementRate is returned as an
        // array. The elementId is retrieved from somewhere...
        const rates = elements.map(elementId => target.elementRate(elementId));

        // Returns the highest element Rate from the rates array.
        return Math.max(...rates);
    } else {
        return 1;
    }
};

I can't figure out where elementId is being set. Obviously it's being set by the game, because logging that through the console will return an undefined error.
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
2,759
Reaction score
2,108
First Language
EN
Primarily Uses
RMMZ
The Array#map method iterates over all elements, transforming them according to a given callback function. In this case: element ID becomes the target's element rate for that ID. The callback function here is written as an arrow function: elementId is the name given to that arrow function's first argument.

Here are a couple of links for more details:
 

Arctica

Veteran
Veteran
Joined
Jul 19, 2021
Messages
64
Reaction score
58
First Language
English
Primarily Uses
RMMZ
Thank you for that, although I had already read up there on Array.prototype.map, your explanation was clearer and I was able to 'see' what is actually happening.

From the logging I did:
[3,3].map(elementId => target.elementRate(elementId)) = [ice, ice] = [2, 2] (the element multipliers)
 

Latest Threads

Latest Posts

Latest Profile Posts

It makes sense that you try to focus on the squishy mages at the back of the party first, right? If the mage can out-DPS the enemy DPS before the latter can kill the tank in front, the fight becomes boring.
finally got footage of my main character running around the main hub world. I've fixed a few things tho even since this video unsurprisingly lol.
 …I think I might need to switch from standard ATK/DEF up/down buffs to parameter altering states. I just had an actor whose usual attack against an enemy does ~25 do a buffed attack against a debuffed enemy for ~600…
just saw that titan quest is free on steam until the 23rd

Forum statistics

Threads
115,227
Messages
1,088,237
Members
149,821
Latest member
thevoidyvoid
Top