Self-Switches by Script

I've looked all over the internet and the documentation for RPG Maker XP, but I can't seem to find the answer to this question. My question is how do I control an event's self switches in a script call? Something like: self-switch(A)= true.
The state of the self switches are stored in $game_self_switches which is the instance of the class Game_SelfSwitches, so check that out. I'd also recommend checking out 'command_123' of the Interpreter class as that's the event code for changing self switches.
I know you are using XP, but here is the Ace script call which may provide a clue for what you need to do with your version of Ruby

$game_self_switches[[map id, event id, "self switch"]] = value

So for event 39 on map 27, where you want the A switch to be turned ON, the call would be

$game_self_switches[[27, 39, "A"]] = true

to turn it off , it would be false
"$game_self_switches[[map_id, event_id, 'self_switch']] = value" works fine for VX Ace, but in XP, it doesn't work at all.

"$game_self_switches[[map_id, event_id, 'self_switch']] == value"   (yes, it's a double equal sign) works correctly when used in the conditional branch.

So I assume that there's either something buggy about the interpreter, or there might be another way to control another event's self switch.
Hmm. Would the self-switch be a capital or lower case letter? I tried both and while I don't get an error, it appears as if though nothing happens when the player interacts with the event.
Yes, it does work in XP.


The difference between XP and Ace is that in XP, the Game_Interpreter script (which takes care of the Control Self Switch command) tells the map to refresh after a self switch has been changed, but in Ace, the Game_Self_Switches class is what tells the map to refresh.


This means if you script a self switch change in Ace, the map refreshes automatically, but in XP it doesn't. You need to add that call as well.


So, as suggested by MobiusXVI, look at XP's Game_Interpreter class at command_123 and see what ELSE it does when you change a self switch using the event command. Make sure your script call does the same.
I've looked under command_123, and it says to also make a self-switch key(key = [$game_map.map_id, @event_id, @parameters[0]]). I looked up what a self-switch key is, and it basically initializes the self-switch. The only other part of the code under the "def command_123" command is an "if" statement. It says "if @event_id > 0", which is, according to the comment, a check for whether the event id is valid or not. I've experimented with several different combinations and they either give me a syntax error or nothing happens despite using the screen refresh. The only thing I haven't been able to experiment a lot with is the indentation, as I'm not sure how many spaces an indent should be in an event script call. What indentation should I use in an event script call? I know it's two spaces in the script editor, but I'm not sure about the script call. Sorry, I only have minimal knowledge of Ruby's scripting system in RPG Maker.
It's what happens AFTER the self switch change that you're interested in. I did talk about the map needing to be refreshed.

Code:
$game_self_switches[[mapid, eventid, "A"]] = true$game_map.need_refresh = true
I figured out what I did wrong! I had the "A" part of the switch surrounded with single quotes instead of double quotes. I also have the correct refresh code now. Thank you!
Nope, that doesn't make a difference. The refresh code is what you were missing.
Great! Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/self-switches-by-script.45732/