MZ Self-Switching Event "B" from Event "A"

I had a thought in the shower... Is it possible to trigger a self-switch from EVENT B off from EVENT A (via a short simple line of script input inside the "change movement route" category)? The purpose would be to spare actual switches (less clutter down the line).

Thank you. 🙂
Yes, it absolutely is.

It's a bit clunky by default though, so I'd recommend adding a plugin to make it easier. For MV, there's Galv's Move Route Extras plugin. With that installed, you'd just write something like this in the move route script:

JavaScript:
this.sswitch('A', true)
this.sswitch('A', false)

The plugin likely works on MZ too, but even if it doesn't, it's trivial to implement. You could just load this as a plugin instead:

JavaScript:
Game_Event.prototype.sswitch = function(letter, value) {
    let key = [$gameMap.mapId(), this.eventId(), letter];
    $gameSelfSwitches.setValue(key, value);
};

Note that the above will crash if you put that in a player move route. I think Galv's plugin checks and makes it do nothing instead, but I could be wrong.
Not sure if you can put it in a moveroute, but you can use
Code:
$gameSelfSwitches.setValue([MAPID, EVENTID, 'A'], true);
You definitely can. You'd substitute EVENTID with this.eventId() in a move route, and MAPID would be $gameMap.mapId(). In other words, basically what I posted above, just without the convenience wrapper.
Thanks in advance, you two! SGHarlekin Oh, I could use that on Event Command > Advanced > Script? Gotcha. Well I'll test Harlekin's method first tomorrow morning, but Ill screenshot both just in case (never know).

Solar, whats the distinction between doing EVENTID and this.eventId()?
EVENTID is just a placeholder. So, if you put it in as a literal, that won't work. You have to substitute it with something that resolves to the ID of an event. In a script command (whether event script or move route script), this.eventId() resolves to the ID of the current event. (In a move route, it's the event that's moving, not the event that set the move route.) It can also resolve to 0 though. Mostly that happens in troop events, but could also happen in common events. (I think common events called by a map event return the ID of the calling event but I could be remembering wrong.)

Ultimately what that means is that you can put in the ID of any event on the map and you'll set a self switch for that event.
It's a bit clunky by default though, so I'd recommend adding a plugin to make it easier. For MV, there's Galv's Move Route Extras plugin. With that installed, you'd just write something like this in the move route script:

What you are doing is basically overkill, but that topic gives me an idea I implement into the EVO Ecosystem... 🙂

You could always keep a simple rule in mind:
Use self-switch targeting for local map/event state. (ONLY!)

Use normal switches/variables for global game state, quests, systems, progression, or anything that must stay readable later.

Reason: event IDs are fragile.
If you delete/recreate events or move logic between maps, 12 may no longer mean the same thing. So this is clean for local mechanical event behavior, doors, traps, cutscene helpers, temporary page changes, etc. But for important global story/progression logic, real switches or variables are still better.
EVENTID is just a placeholder. So, if you put it in as a literal, that won't work. You have to substitute it with something that resolves to the ID of an event. In a script command (whether event script or move route script), this.eventId() resolves to the ID of the current event. (In a move route, it's the event that's moving, not the event that set the move route.) It can also resolve to 0 though. Mostly that happens in troop events, but could also happen in common events. (I think common events called by a map event return the ID of the calling event but I could be remembering wrong.)

Ultimately what that means is that you can put in the ID of any event on the map and you'll set a self switch for that event.
Re-reading you (after trying the script), I get what you meant now. As I pasted it, I wondered "Well where do I put the numbers? Do I add some parentheses or something?" But I tried changing the placeholders (as you said earlier) and it worked on the first try. In retrospect (fresh from sleep), it was a dumb question on my part.


Works great, thanks everyone. I've tried both in move route and as a standalone script.

Original thread: https://forums.rpgmakerweb.com/threads/self-switching-event-b-from-event-a.183999/