$gameMap._events[i]._characterName.indexOf (solved)

Hi guys.


What is the right way to do this


i need found the name of file or event!, of each event on map to check if the name are 'monster'


Tank you

Code:
if (command === 'MonsterMover') {

    //calculate how mutch event have the name monster
    for (i = 1; i <= $gameMap._events.length; i++) {

        //If The indexof return -1 , is because is not monster, if return 1 is a monster                                         
        if ($gameMap._events[i]._characterName.indexOf("monster")) {

            //do something with this event ..                                   
            console.log(i + ' monster found ');
        }
    }
}
There are several valid methods to do what you are wanting. The for loop is a good choice as that will allow you to break out of the loop if you are wanting or expecting to find only one match. You can also do the following :

Code:
var tmpMonster = $gameMap._events.filter(function(event) {
  return event._characterName.includes('monster');
});

// tmpMonster is an array with all the events with the character name of 'monster'.
There are several valid methods to do what you are wanting. The for loop is a good choice as that will allow you to break out of the loop if you are wanting or expecting to find only one match. You can also do the following :



var tmpMonster = $gameMap._events.filter(function(event) {
return event._characterName.includes('monster');
});

// tmpMonster is an array with all the events with the character name of 'monster'.

wow


I dont understant this 


.filter(function(event)


But is work very well !


tanks you friend

Original thread: https://forums.rpgmakerweb.com/threads/gamemap-_events-i-_charactername-indexof-solved.67249/