Need a snippet to: selfswitch D on all events on map that has the specific "word" in filename.png

Hello

Need a snippet to activate selfswitch D on all events on map that has the specific "_word" in filename.png

I need something like this:
if($gameMap.event().characterName().contains("_word")) { var key = [$gameMap._mapId,???, 'D']; $gameSelfSwitches.setValue(key, true); } }}

I dunno how to switch them all at once. I would be so happy if anyone could help me out with a working version of this 😀 <3
This might do it:
JavaScript:
var word  = '_word';           // filename search term
var mapId = $gameMap.mapId();  // current map ID
var sswId = 'D';               // self-switch ID
$gameMap.events().filter(function(ev) {  // filter out relevant events
  return ev.characterName().contains(word);
}).forEach(function(ev) {                // switch their switches
  $gameSelfSwitches.setValue([mapId, ev.eventId(), sswId], true);
});
Incidentally, this sounds like a very roundabout way of doing things, but it's your project~ 😅
Thank you!
haha yeah it might be a roundabout thing to do. Tell me if you know of a better way.
Thing is, Im copying allot of events in a ring around the player, and when the player clicks on one of the events with a mouse it goes there. Maybe I have eventet myself into a corner, but I can't erase those copied events properly. So solution maybe that the events around the player has _word in filename, that way I can tell the game that if this, then "Your script" and it will run selfswitch D on all the events that matter for this, without me having to find any additional info like ID and such.

Tested with the code provided and it just runs smooth now, my game has even gotten it's fps back when doing this
Oh, I see! Well, it depends how you've "copied" those events there, but if it's some kind of event spawner plugin then I'd expect a "despawn" or "remove" function. If you need help with getting a specific plugin to work as expected then it'd be best to start a new thread (if you haven't made one already) in Plugin Support. 🙏

Good to hear this is working for you, though~ 😂

Original thread: https://forums.rpgmakerweb.com/threads/need-a-snippet-to-selfswitch-d-on-all-events-on-map-that-has-the-specific-word-in-filename-png.118159/