start event by name[solve]

solve
I create a function for it
Code:
callEventbyName = function(name){
    for (var i = $dataMap.events.length - 1; i > 0; i--) {
        var event = $dataMap.events[i];
        if (event.name === name) {
            $gameMap.event(i).start();
            break;
        }
    }
}
.......................................................................
now I use
$gameMap.event(3).start();
to force start event from my custom window minigame
because I use show text and other thing from that event setting
but that is a bit annoying when every time
I have to check what number of the event I use
because I make many version of map and copy it around
the number change a lot

I want to call it by event name is it possible?
like I name it
water pump fail
so I specific call event name 'water pump fail' to start
thank you
Glad you solved it but... more info in case you want...
Code:
$dataMap.events.filter(function (item) {if (item) {return (item.name === this.name)};}, {name:'Event Name Goes Here'})
That returns an array of the events that the names match the 'Event Name Goes Here' 😉

So that means with just 1 or 2 lines of code...
You could do something like this:
Code:
$gameVariables.setValue(1,($dataMap.events.filter(function (item) {if (item) {return (item.name === this.name)};}, {name:'Event Name Goes Here'})));
$gameVariables.value(1).forEach(function (v){$gameMap.event(v.id).start();})
...to run all events with the same name 😉
Glad you solved it but... more info in case you want...
Code:
$dataMap.events.filter(function (item) {if (item) {return (item.name === this.name)};}, {name:'Event Name Goes Here'})
That returns an array of the events that the names match the 'Event Name Goes Here' 😉

So that means with just 1 or 2 lines of code...
You could do something like this and run all events with the same name 😉
Code:
$gameVariables.setValue(1,($dataMap.events.filter(function (item) {if (item) {return (item.name === this.name)};}, {name:'Event Name Goes Here'})));
$gameVariables.value(1).forEach(function (v){$gameMap.event(v.id).start();})
thank you... but I still don't understand the filter/forEach(function)
seen it a lot but still confuse about it
so I use for loop that I understand
and that one long line code is the other thing that hurt my little confuser artist's brain a lot... :hswt:

Original thread: https://forums.rpgmakerweb.com/threads/start-event-by-name-solve.119661/