What's wrong with this code?

I'm brand new to js and I've been trying to run code that turns off a self switch when a variable reaches 2.
Here is the code:

if $game_variables[2] == 2 {

$gameSelfSwitches.setValue(A, false)

};

It says unexpected identifier. Please help me understand the issue! Thanks in advance.
$gameSelfSwitches.setValue (NUMBER, STATE)
I beleive you need the number of the event, not the letter of the self switch.
$gameSelfSwitches.setValue (NUMBER, STATE)
I beleive you need the number of the event, not the letter of the self switch.
But there are 4 self switches, how does it know which one I'm talking about if I substitute the switch ID for the event ID? Also, the code is in the event that I want the self switch changed in, so I don't think I need to specify the ID of the event. If that is the case, though, where would I put the letter of the self switch? (eventID, A-D, state)?
Firstly, why would you need js code for this? You could do this with simple eventing?

Anyways, to do what you're trying to do, the script call would be:

Code:
if ($gameVariables.value(2) === 2) {
$gameSelfSwitches.setValue([mapID, eventID, "A"], false);
};

Replace mapID with the id of the map the event is in.
Replace eventID with the id of the event.


If the code is in the event that you want to change the self switch of, then you can simply use this without having to put in mapID or eventID:

Code:
if ($gameVariables.value(2) === 2) {
$gameSelfSwitches.setValue([this._mapId, this._eventId, "A"], false);
};
Firstly, why would you need js code for this? You could do this with simple eventing?

Anyways, to do what you're trying to do, the script call would be:

Code:
if ($gameVariables.value(2) === 2) {
$gameSelfSwitches.setValue([mapID, eventID, "A"], false);
};

Replace mapID with the id of the map the event is in.
Replace eventID with the id of the event.


If the code is in the event that you want to change the self switch of, then you can simply use this without having to put in mapID or eventID:

Code:
if ($gameVariables.value(2) === 2) {
$gameSelfSwitches.setValue([this._mapId, this._eventId, "A"], false);
};

Thank you!

Original thread: https://forums.rpgmakerweb.com/threads/whats-wrong-with-this-code.81702/