Script-Call to flip self-switches of specific events on the current map?

Here is what I'd like to do:

You interact with an event, which then causes all events on the current map with name X to flip their self-switch A.

Is there a script-call to do this?



For some context:

I have altars as a gameplay mechanic which allow the player so sacrifice items to gain rewards.
Once you proceed with the sacrifice, multiple torches around the altar are extinguished.

Now, there will be a lot of these torches around each altar, and there will be a lot of altars. So I'd help to make the whole process cleaner without making a lot of copy-pasting.

I am looking for something along these lines:
(Obviously this is not actual code, but rather a logical representation)

Code:
For X (each event) on the current map:
    if event.name === "Altar Torch":
       $gameSelfSwitches.setValue([CURRENTMAP,X,'A'], true);
Well, you would know when you're designing the map which events are torches. So you can simply specify all the events in one call:
Code:
[X, Y, Z].forEach(eventId => $gameSelfSwitches.setValue([MAP, eventId, 'A'], true));
where MAP is the id of the map, and X, Y, Z are the IDs of the torch events (however many you want).

You could also just use one of your game switches, and give all of the torch events a condition for that switch instead of a self switch.
$gameMap.events().forEach(event => event.event().name === "Altar Torch" ? $gameSelfSwitches.setValue([$gameMap.mapId(), event.event().id, 'A'], true) : "")
Well, you would know when you're designing the map which events are torches. So you can simply specify all the events in one call:
Code:
[X, Y, Z].forEach(eventId => $gameSelfSwitches.setValue([MAP, eventId, 'A'], true));
where MAP is the id of the map, and X, Y, Z are the IDs of the torch events (however many you want).

You could also just use one of your game switches, and give all of the torch events a condition for that switch instead of a self switch.
This is a fine solution, but still requires some admin in remembering to populate the array with the IDs of all the torch events, and you'd have to redo that for every altar so adding new ones would be a bit of busywork. My solution negates the need for this; as long as you name the event correctly you need do nothing else for it to function.

Edit: Didn't mean to double post, I was trying to add this to my first one and it posted as a new one instead. Sorry!
@ATT_Turan
That makes sense to me.
However, this whole thing is more of a quality of life improvement for me rather than integral to the game.

Also, as I said, there will be many instances of these altars and their respective Torches.
So using different switches for each instance seems a little tiresome.

What you proposed is a huge improvement over what I did before, but still requires a tiring amount of event-checking since most of these "Torch Events" don't have incremental event ID's so I'd have to check each ID individually which is also annoying.

And this for every map and every Torch.

But thank you nonetheless for your help as always!

@Trihan
Thank you, this is exactly what I was looking for.
And it seems to work perfectly, thank you very much.
@ATT_Turan
That makes sense to me.
However, this whole thing is more of a quality of life improvement for me rather than integral to the game.

Also, as I said, there will be many instances of these altars and their respective Torches.
So using different switches for each instance seems a little tiresome.

What you proposed is a huge improvement over what I did before, but still requires a tiring amount of event-checking since most of these "Torch Events" don't have incremental event ID's so I'd have to check each ID individually which is also annoying.

And this for every map and every Torch.

But thank you nonetheless for your help as always!

@Trihan
Thank you, this is exactly what I was looking for.
And it seems to work perfectly, thank you very much.
Lifehacks like this with self switches are a personal guilty pleasure of mine. I had to do something similar with applying an effect to events with a specific name back in an event game I made where you had to make a game comprised almost solely of sidequests; I had one where you had to collect kittens, and I made a cool kitten radar that calculated what direction the closest kitten to you was in.
This is a fine solution, but still requires some admin in remembering to populate the array with the IDs of all the torch events

What you proposed is a huge improvement over what I did before, but still requires a tiring amount of event-checking
I was operating under the assumption that you'd have your map finished before doing the coding for the altars; at which point, it's less typing to make a list of the IDs than it is to rename them all "Altar Torch" 😉 But if you've already done that, then absolutely Trihan's answer is better for you.
I was operating under the assumption that you'd have your map finished before doing the coding for the altars

Well you aren't even entirely wrong about with that assumption.

Your suggestion works well even on non-completed maps because then each new event has the previous' event ID +1.

However, on many completed maps, I deleted and added events countless times already, and as such,
any new event created will fill out any event ID that was previously occupied but later deleted, which creates the problem I described earlier about the "Torch Event" IDs being scrambled.

Additionally, the implementation of these events happened during development, which means that I added these events on previously finished maps retroactively.
Do altar torches have a unique image?

If so, we can filter on _characterName instead of .name, and use the image file name. No need to rename events.

(If you're using one of the multisprite sheets and there's a collision you'll have to dig into ._characterIndex as well)
@Restart
That's a nice info going forward, but in my particular case not really necessary.
The torches have no functionality beyond being an aesthethic prop. They may have different sprites (for different flame colors), but the image for the extinguished torch is always the same.

As such, I just copy paste these torches everywhere I need them and they all have the same name.

If for some reason I have 2 altars on a map, I just change the torches name to
"Altar Torch1" and "Altar Torch2" and change the script call of their respective altar accordingly.

Original thread: https://forums.rpgmakerweb.com/threads/script-call-to-flip-self-switches-of-specific-events-on-the-current-map.136391/