Asking for help modifying a plugin

Hello. I'm trying to modify Galv's Puzzle Functions script. Here's his terms of use.

I suppose I could have put this in Plugin Requests, but I decided it probably belongs here, because I want to understand why what I'm doing isn't working.

The original script allows you to trigger an adjacent event's Self Switch. For example, if you put this in an autonomous move route command's script field:

Code:
Galv.PUZ.switch('front','A','on',this._eventId);

then is will turn Self Switch A on for any event that is directly in front of the event. I'm trying to make it so that it changes a regular switch instead of a self switch. So if you wanted to flip switch 99 on, you would use:

Code:
Galv.PUZ.switch('front','99','on',this._eventId);

So here's what I did.

The original script is 17 KB and 435 lines, but the following is just part of it and is 3 KB and just surprisingly 73 lines (not including blank lines). I've removed everything that isn't necessary (the plugin has several other features that are irrelevant to this), I've commented out the 4 lines that I've changed with "\\OLD", which is immediately followed by the new, modified line (which is followed by "//NEW".

If you were to comment out the lines followed by "//NEW", and remove the leading "//OLD" comments, then the script works as expected for changing self switches. As it is below, however, nothing happens at all. I was wondering why.

Oh, one other thing, almost forgot. I changed a couple of var names. I changed "letter" to "number" and "key" to "num", just so it would make more sense.

Any help is much appreciated.

Code:
var Imported = Imported || {};
Imported.Galv_PuzzleFunctions = true;

var Galv = Galv || {};          // Galv's main object
Galv.PUZ = Galv.PUZ || {};      // Galv's stuff

//-----------------------------------------------------------------------------
//  CODE STUFFS
//-----------------------------------------------------------------------------

(function() {

Galv.PUZ.switch = function(dir,number,state,eventId) {
    var dirs = [];
   
    switch(dir) {
        case '4dir':
            // do 4 directions
            dirs = [2,4,6,8];
            break;
        case 'front':
            // get event's direction
            if (!eventId) var eventId = $gameMap._interpreter._eventId;
            dirs = [$gameMap.event(eventId).direction()];
            break;
        case 'event':
            if (!eventId) var eventId = $gameMap._interpreter._eventId;
            var num = [$gameMap.mapId(), $gameMap.event(eventId).eventId()];
//OLD            var currentState = $gameSelfSwitches.value(num);
            var currentState = $gameSwitches.value(num); //NEW
            var state = Galv.PUZ.getSwitchState(state,currentState);
//OLD            $gameSelfSwitches.setValue(num, state);
            $gameSwitches.setValue(num, state); //NEW
            return;
            break;
        default:
            dirs = Array.isArray(dir) ? dir : [dir];
    };
   
    Galv.PUZ.doSwitches(dirs,number,state,eventId);
};

Galv.PUZ.doSwitches = function(dirs,number,state,eventId) {
    // For each direction
    if (eventId != undefined) {
        var char = eventId > 0 ? $gameMap.event(eventId) : $gamePlayer;
    } else {
        var char = $gameMap.event($gameMap._interpreter._eventId);
    };

    if (char) {
        for (var i = 0; i < dirs.length; i++) {
            // get all events in that direction
            var direction = dirs[i];
            if (direction > 0) {
                var x = $gameMap.roundXWithDirection(char.x, direction);
                var y = $gameMap.roundYWithDirection(char.y, direction);
            } else {
                var x = char.x;
                var y = char.y;
            };
            var eventList = $gameMap.eventsXy(x,y);
            // do switch for all events
            for (var e = 0; e < eventList.length; e++) {
                var event = eventList[e];
                if (event.event().meta.puznope) continue;
                var num = [$gameMap.mapId(), event.eventId(), number];
//OLD                var currentState = $gameSelfSwitches.value(num);
                var currentState = $gameSwitches.value(num); //NEW
                var setState = Galv.PUZ.getSwitchState(state,currentState);
//OLD                $gameSelfSwitches.setValue(num, setState);
                $gameSwitches.setValue(num, setState); //NEW
            };
        };
    };
};

Galv.PUZ.getSwitchState = function(state, currentState) {
    switch(state) {
        case true:
        case 'on':
            var set = true;
            break;
        case false:
        case 'off':
            var set = false;
            break;
        case 'flip':
            var set = !currentState;
            break;
    };
    return set;
};
})();
Self switches are identified by an array indicating the map id, event id and letter. But switches are just identified by a number. My quick browse of the code shows that you can just comment out var num = ... in the original code and replace "num" by "number" in your new code.
just comment out var num = ... in the original code and replace "num" by "number" in your new code

That did indeed work, thanks! Unfortunately, it doesn't work with Yanfly's Self Switches and Variables which makes it not very useful. The idea was that I could have a bunch of different self switches instead of just 4. So I'll try to sort that out next.

Original thread: https://forums.rpgmakerweb.com/threads/asking-for-help-modifying-a-plugin.120726/