how can I activate a switch in route?

I added this script in movement route
$gameSelfSwitches.setValue("A", true);
but it didn't work

is there any method open switch from route?
use the command "switch ON/OFF" in the moveroute command window for regular switches.

Self-Switches can't be directly accessed, if you go by script you'll need the full script command stating which map and which event the switch is part of.
You can find that script call and many more in the RPG Maker MV Script Call spreadsheet. It's pinned to the top of the RPG Maker MV forum here.
ok... thank you
actually I am reference to this list
so I wonder if it requires different method to type it in the route...

what if I want a random probability to open a switch?
how can I do this?
actually I am reference to this list
then you copied it wrongly because the command you gave is NOT the correct one.

what if I want a random probability to open a switch?
how can I do this?
random effects inside a move route are difficult. Please state what you want to do instead of how you want to do it, then we can help you better.
(the switch is only a method, it does not do anything in itself - we need to know what it is supposed to do)
well...
I want to make a monster event keep chasing the player
there is different event page inside it
which is different movement style
and trigger different event if touching the player

the monster will chase the player for several steps
than a random chance to shift to different movement style
You can use this Scriptline in Autonomous Moveroute to turn the Self Switch A of "This Event" on "This Map" to On.
Code:
$gameSelfSwitches.setValue([$gameMap.mapId(), this._eventId, 'A'], true)
it might work, but you need to make it a bit longer than selfswitches, because it doesn't say which selfswitch,

$gameSelfSwitches.setValue([$gameMap.mapId(), this.eventId(), 'A'], true);

That code might work, but you also need an A switch active and do things, and if you need to revert it back
you use the following

$gameSelfSwitches.setValue([$gameMap.mapId(), this.eventId(), 'A'], false);

But Idk if you want something of its only the same event or in multiple maps.

But I hope you can achieve what you need though =)
But self switch can also be activated by a moveroute and simply use SelfSwitch command ON.


@Bex you just got me first D:
thanks for all help!

>>But self switch can also be activated by a moveroute and simply use SelfSwitch command ON.
where can I find this command?
I try the script its work
but how can I set a probability on it?

lets say when the monster walk towards player for 10 steps
then a check command will run, 50% chance to run the script to turn on the switch
1. You walk 10 Steps with autonomous Moveroute on Eventpage1.
2. You activate Self Switch A
3. That Self Switch is used as Page Condition for a Higher Page ID which runs on Parallel (Eventpage3).
4. Make the Calculations on that Page, turn Self Switch A OFF and depending on the outcome you turn Self Switch B ON or not.
5. Self Switch B is used a Pagecondition (Eventpage2).

Eventpage 1 and 2 would be different chasing movement, while Eventpage 3 would do the Calculation when activated.
But i see a Problem with this, it could happen that the monster stops chasing you if to far outside of visible Screen.

Thats why i would recomment an extra Parallel Event which contains all the Conditions and Movecommands for the Monster.
That Event will just give the Commands to the Monster when needed, thatway it also Moves if far outside of visible Screen.
Edit:
It should be possible to do such a probability Check in the Autonomous Moveroute itself, but i have no clue about how that would be written. I recomment the controlling Event solution for better overview and readability.
then a check command will run, 50% chance to run the script to turn on the switch
It should be possible to do such a probability Check in the Autonomous Moveroute itself, but i have no clue about how that would be written.
random number checks in a single script line are theoretically possible, but extremely difficult to handle as you need too many commands there.
better would be to always switch to a parallel process page, and then have a random check at that page to determine whether to go back to the original page without doing anything or to proeed to a page with a different move pattern.

But self switch can also be activated by a moveroute and simply use SelfSwitch command ON.
where can I find this command?
There is no such command for self-switches, only a command for regular switches.
For self-switches you need to use the script command with the correct key for the self-switch (that is what the OP did wrong originally, "A" is NOT a correct key to identify a self-switch, the correct syntax has been give in the answers above)
50% chance added to @Bex's answer:
Code:
if (Math.random() < 0.5) $gameSelfSwitches.setValue([$gameMap.mapId(), this._eventId, 'A'], true);
But yes, probably better to do this with a separate event due to off-screen event handling.
thanks all!
Thread closed IgnoreMe

Original thread: https://forums.rpgmakerweb.com/threads/how-can-i-activate-a-switch-in-route.113119/