gydiwon

Villager
Member
Joined
Aug 25, 2019
Messages
12
Reaction score
4
First Language
English
Primarily Uses
RMMV
I learned to access an event by it's ID using $gameMap.event(eventID), but event ID's can vary depending on the order in which they were added to the map. I'd like to access an event by its name instead. In Javascript, how do I access an event by its name?
 

OcRam

Servant of the Universe
Veteran
Joined
Aug 2, 2016
Messages
679
Reaction score
827
First Language
Finnish
Primarily Uses
RMMZ
$gameMap.event(eventID)
I learned to access an event by it's ID using $gameMap.event(eventID), but event ID's can vary depending on the order in which they were added to the map. I'd like to access an event by its name instead. In Javascript, how do I access an event by its name?
Hi there!

It should be: $gameMap.event(1).event().name

Edit: Oh I don't know how to read.... :D

Code:
// Event array
$gameMap.events().filter(ev => {
    return (ev) ? ev.event().name == "event_name" : false;
});

// First occurance
$gameMap.events().find(ev => {
    return ev.event().name == "event_name";
});
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
32,365
Reaction score
8,087
First Language
German
Primarily Uses
RMMV
the name is a sub-property of the event and you can't use it as a direct reference.

what you can do is check all events for a name and store/remember the IDs of the events where the name fits, then use those IDs as further reference.
 

gydiwon

Villager
Member
Joined
Aug 25, 2019
Messages
12
Reaction score
4
First Language
English
Primarily Uses
RMMV
Thanks OcRam! With your help, I was able to create this handy function so I could search an event by name.
Code:
findEventByName = function(event_name) {
    var myEvent = $gameMap.events().find(ev => {
        return ev.event().name == event_name;
    })
    return myEvent;
}
 

OcRam

Servant of the Universe
Veteran
Joined
Aug 2, 2016
Messages
679
Reaction score
827
First Language
Finnish
Primarily Uses
RMMZ
Also
Thanks OcRam! With your help, I was able to create this handy function so I could search an event by name.
Code:
findEventByName = function(event_name) {
    var myEvent = $gameMap.events().find(ev => {
        return ev.event().name == event_name;
    })
    return myEvent;
}
And if you want to bind function to Game_Map then:

Code:
// Array of events
Game_Map.prototype.findEventsByName = function (event_name) {
    return this._events.filter(ev => {
        return (ev) ? ev.event().name == event_name : false;
    });
};

// Or first occurance
Game_Map.prototype.findEventByName = function (event_name) {
    return this._events.find(ev => {
        return ev.event().name == event_name;
    });
};

// Usage would be: $gameMap.findEventByName('My_Event');
 

Latest Threads

Latest Posts

Latest Profile Posts

oddly enough, at this point... 3 major things have kept me from porting my project to MZ... animations, and that's mainly because they don't match the artstyle of my game. and two... I NEED a YED Sideview Battler like plugin and I have yet to see one. 3rd, I don't have the money for all the stuff I need plugin wise. and I already have it on MV... lol
Generally speaking, would there be interest in some form of tutorial regarding general project management? I see there are a lot of indie/self-taught devs around here, and looking back i feel like there was a lack of resources on how to properly manage a project that might take several years to finish
I've been working on some ABS team A.I. for 'A New Suburbia', and thought I'd share.

I'm generally quite please although the AI is a little grenade heavy right now :rolleyes: - Sneaking and stalking next! Please excuse the terrible map... it was just for ease of viewing!
Voting for the second round of the Map Madness Tournament is now live! Vote for your favorite in each matchup! https://forums.rpgmakerweb.com/index.php?forums/map-madness-2021-polls.187/
Just bought the Visustella All Waves bundle... Time to go IN!!

Forum statistics

Threads
110,577
Messages
1,054,353
Members
143,693
Latest member
speedylmao
Top