Help with code that check for the enemy troop states?

Hi all!!
I just want to know how can i check for how many states the enemy troop (all the enemies) have.


Thanks!!
Hi,
Our enemies are contained within a list (array) that is contained within the object of $gameTroop.
  • The list of our enemies is named "_enemies" and so we can get to it by calling "$gameTroop._enemies"
The enemies contain many properties and one is states which is just a list (array) contained within the enemy.
  • The list of the states is named "_states" and so we can get to it by calling "$gameTroop._enemies._states"
    • Where "i" is a variable (like 0, 1, 2, etc.)







Finally we are going to use this knowledge plus a loop (example "for" loop) in order to count the number of states.
Code:
var statesCount = 0;
for (var i = 0; i < $gameTroop._enemies.length; i++) {
statesCount += $gameTroop._enemies[i]._states.length;
};
At the end, this variable stateCount will contain the total number of states that the enemies have.
You sir. are DA BOMB at explaining, thank you so much!

Original thread: https://forums.rpgmakerweb.com/threads/help-with-code-that-check-for-the-enemy-troop-states.87396/