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

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,440
First Language
French
Primarily Uses
RMMV
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 ');
        }
    }
}
 
Last edited by a moderator:

Ossra

Formerly Exhydra
Veteran
Joined
Aug 21, 2013
Messages
1,076
Reaction score
856
First Language
English
Primarily Uses
RMMV
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'.
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,440
First Language
French
Primarily Uses
RMMV
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
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

"You can thank my later", "But you haven't done anything", "Well, that's why ..."
Are we allowed to post about non-RPG Maker games?
I should realize that error was produced by a outdated version of MZ so that's why it pop up like that
Ami
i can't wait to drink some ice after struggling with my illness in 9 days. 9 days is really bad for me,i can't focus with my shop and even can't do something with my project
How many hours have you got in mz so far?

Forum statistics

Threads
105,884
Messages
1,017,243
Members
137,609
Latest member
shododdydoddy
Top