Asking for help modifying a plugin

JDevain

Veteran
Veteran
Joined
Oct 21, 2018
Messages
121
Reaction score
46
First Language
English
Primarily Uses
RMMV
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;
};
})();
 

SeaPhoenix

Veteran
Veteran
Joined
May 14, 2015
Messages
252
Reaction score
233
First Language
English
Primarily Uses
RMMV
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.
 

JDevain

Veteran
Veteran
Joined
Oct 21, 2018
Messages
121
Reaction score
46
First Language
English
Primarily Uses
RMMV
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.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.
time for a new avatar :)

Forum statistics

Threads
106,017
Messages
1,018,356
Members
137,802
Latest member
rencarbali
Top