- 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:
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:
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.
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);
Code:
Galv.PUZ.switch('front','99','on',this._eventId);
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;
};
})();
