Arctica

Veteran
Veteran
Joined
Jul 19, 2021
Messages
71
Reaction score
72
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,771
Reaction score
2,122
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
71
Reaction score
72
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 Profile Posts

Tiamat-86 wrote on ATT_Turan's profile.
apparently since its turning 15 years old this year the ps3 is considered "retro". now how old do you feel?
guess that means im an "antique" gamer since ill still play games as old as i am.
"you know your getting old when your childhood console changes ethnicity" lol it turned yellow
I'm making Toilet in Wonderland 2. and tell vinny about it lol
WE ARE THE BORG. YOUR BIOLOGICAL AND TECHNOLOGICAL DISTINCTIVENESS WILL BE ADDED TO OUR OWN. RESISTANCE IS FUTILE.
D2R save files are so broken. how was the beta test better then the full release. blizzard's last hope crashed and burned.
they're getting no more chances from me.

Forum statistics

Threads
115,338
Messages
1,089,140
Members
150,013
Latest member
keda27
Top