Since the objects in the `$gameTroop._enemies` is going to change a lot though out the game, I found that I would want grab the agi of every enemy in that array and combine it into one. What is the correct syntax to do this?
MZ Garbing the combined agi value of enemies in $gameTroop._enemies Array.
Learning JavascriptThere's already a method for that in the engine, see the following:
If you don't want the agility sum to be divide at the end, then just modify the method as you see.
JavaScript:
Game_Unit.prototype.agility = function() {
const members = this.members();
const sum = members.reduce((r, member) => r + member.agi, 0);
return Math.max(1, sum / Math.max(1, members.length));
};
If you don't want the agility sum to be divide at the end, then just modify the method as you see.
Only read variables with underscore in their names when there's no other way! The underscore indicates that this variable is "private" and should not be accessed. Write
$gameTroop.members() instead.Original thread: https://forums.rpgmakerweb.com/threads/garbing-the-combined-agi-value-of-enemies-in-gametroop-_enemies-array.167112/