- Joined
- Oct 15, 2012
- Messages
- 48
- Reaction score
- 25
- First Language
- English
- Primarily Uses
- RMMV
Persistent Data v5
RPG Maker MV Plugin
Jackkel Dragon
Introduction
A quick and simple plugin to allow the use of persistent switches (which do not reset their values between saved games).
Features
The ability to set switches/variables to be saved to a "persistent" save file, allowing them to persist across save games.
An example of using this could be creating an ending list, or creating New Game+ elements that don't require a clear save file.
How to Use
- Copy the plugin code into a .js file and add it to your project's "js/plugins/" folder. (Be sure to use the name given in the code's header!)
- Load the plugin in RPG Maker MV's plugin manager for your project.
- Modify the persistent switch/variable IDs as needed. More information can be found in the help text.
Notes
- I created this plugin out of necessity for my own project, so it is very bare-bones and probably won't be updated often. Still, I hope it helps until someone comes up with a more expansive and user-friendly way to store persistent data.
Updates
- v1: First release. October 26th, 2015.
- v2: (Hopefully) fixed a problem with deleting MV's default global save data and overwriting default functions. Changed the file persistent data gets saved to from "global" to "filePersistent". (I'll try to change the name later... I couldn't get a custom filename function to work properly.) October 26th, 2015.
- v2 hotfix: Added a function to rename the persistent data file to "persistent". October 26th, 2015.
- v2 hotfix 2: Fixed a problem where loading a saved game would reset persistent switches in some cases. October 26th, 2015.
- v3: Changed the loading code so that it wouldn't re-write the persistent file multiple times on loading a game. October 27th, 2015.
- v4: Added a parameter to turn off automatic saving of persistent data. A general expression parser was provided by ArcherBanish to allow for an undefined number of persistent switches. ArcherBanish also provided two plugin commands that allow forcing a persistent save/load. October 28th, 2015.
- v5: Added support for persistent variables. Note that this requires deleting your persistent save data from earlier versions of the plugin to work.
Plugin Code
v5
//=============================================================================
// JKL_PersistentData.js
//=============================================================================
/*:
* @plugindesc Jackkel's Persistent Data Plugin (v5)
*
* @author Jackkel Dragon
*
* @param Persistent Switches
* @desc The ID of the persistent switches. Formatting example: 1-3,5-6,8,10-11,13
* @Default 1-5
*
* @param Save Switches when Set
* @desc Whether the persistent switches will be saved to the file the moment any switch is set. [true/false]
* @Default true
*
* @param Persistent Variables
* @desc The ID of the persistent variables. Formatting example: 1-3,5-6,8,10-11,13
* @Default 1-5
*
* @param Save Variables when Set
* @desc Whether the persistent variables will be saved to the file the moment any variable is set. [true/false]
* @Default true
*
* @Help
*
* This plugin provides persistent switches and variables that are saved to the
* "Persistent" save file, allowing you to set switches and variables that are
* not tied to a save game. Uses for this could include designing an ending list
* or creating New Game+ elements without requiring the use of a clear save
* file.
*
* The value for each switch/variable in configuration is the switch ID in the
* editor, without any leading zeroes ("10" instead of "0010").
*
* Example: Setting the persistent switches to "1-5,7" will set the switches with
* IDs 1, 2, 3, 4, 5, and 7 to be saved to the persistent data file.
*
* Plugin Command: Persistent Save
* Forces a save of the persistent data file.
*
* Plugin Command: Persistent Load
* Forces the game to load from the persistent data file.
*
* Thanks to "ArcherBanish" for writing the general expression parser
* to allow an undefined number of persistent switches and providing
* the plugin commands.
*
* This plugin is free to use, even in commercial projects. Credit "Jackkel
* Dragon" or "John Cooley".
*
*/
(function() {
var parameters = PluginManager.parameters('JKL_PersistentData');
var _Game_Switches_setValue = Game_Switches.prototype.setValue;
Game_Switches.prototype.setValue = function(switchId, value, save) {
save = typeof save !== 'undefined' ? save : true;
_Game_Switches_setValue.call(this, switchId, value);
if (save && eval(parameters['Save Switches when Set']))
PersistManager.save();
};
var _Game_Variables_setValue = Game_Variables.prototype.setValue;
Game_Variables.prototype.setValue = function(varId, value, save) {
save = typeof save !== 'undefined' ? save : true;
_Game_Variables_setValue.call(this, varId, value);
if (save && eval(parameters['Save Variables when Set']))
PersistManager.save();
};
var _DataManager_createGameObjects = DataManager.createGameObjects;
DataManager.createGameObjects = function() {
_DataManager_createGameObjects();
PersistManager.load();
};
var _StorageManager_localFilePath = StorageManager.localFilePath;
StorageManager.localFilePath = function(savefileId) {
var name;
if (savefileId === "Persistent")
name = StorageManager.localFileDirectoryPath() + "persistent.rpgsave";
else
name = _StorageManager_localFilePath.call(this,savefileId);
return name;
};
var _Scene_Load_onLoadSuccess = Scene_Load.prototype.onLoadSuccess;
Scene_Load.prototype.onLoadSuccess = function() {
_Scene_Load_onLoadSuccess.call(this);
PersistManager.load();
}
//-----------------------------------------------------------------------------
// Persistent Data Manager
//
// The static class that manages the persistent data.
function PersistManager() {
throw new Error('This is a static class');
}
PersistManager.load = function() {
var json;
var persist = {};
try {
json = StorageManager.load("Persistent", json);
} catch (e) {
console.error(e);
}
if (json) {
persist = JSON.parse(json);
}
this.applyData(persist);
};
PersistManager.save = function() {
StorageManager.save("Persistent", JSON.stringify(this.makeData()));
};
PersistManager.makeData = function() {
var persistswexp = parameters['Persistent Switches'];
var switches = XUtil.resolve(persistswexp);
var persistvarexp = parameters['Persistent Variables'];
var variables = XUtil.resolve(persistvarexp);
var persist = {};
persist.switches = [];
persist.variables = [];
for(var x of switches){
persist.switches[x] = $gameSwitches.value(x);
}
for(var y of variables){
persist.variables[y] = $gameVariables.value(y);
}
return persist;
};
PersistManager.applyData = function(persist) {
var persistswexp = parameters['Persistent Switches'];
var switches = XUtil.resolve(persistswexp);
var persistvarexp = parameters['Persistent Variables'];
var variables = XUtil.resolve(persistvarexp);
if(typeof switches !== 'undefined' && typeof persist.switches !== 'undefined'){
for(var x of switches){
if(typeof x !== 'undefined'){
$gameSwitches.setValue(x, persist.switches[x], false);
}
}
}
if(typeof variables !== 'undefined' && typeof persist.variables !== 'undefined'){
for(var y of variables){
if(typeof y !== 'undefined'){
$gameVariables.setValue(y, persist.variables[y], false);
}
}
}
};
PersistManager.readFlag = function(persist, name) {
return !!persist[name];
};
function XUtil() {
throw new Error('This is a static class');
}
XUtil.resolve = function(regex) {
var allsemiexp = regex.split(',');
var semiexp = null;
var semisemiexp = null;
var indexes = new Array();
var curentindex = 0;
for(semiexp of allsemiexp){
semisemiexp = semiexp.split('-');
if(semisemiexp.length > 1){
y = Number(semisemiexp[1]);
for(var x = Number(semisemiexp[0]); x <= y; x++){
indexes[curentindex] = x;
curentindex++;
}
}else{
indexes[curentindex] = Number(semisemiexp[0]);
curentindex++;
}
}
return indexes;
}
var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
_Game_Interpreter_pluginCommand.call(this, command, args);
if (command === 'Persistent') {
switch (args[0]) {
case 'Save':
PersistManager.save(parameters);
break;
case 'Load':
PersistManager.load(parameters);
break;
}
}
}
})();
// JKL_PersistentData.js
//=============================================================================
/*:
* @plugindesc Jackkel's Persistent Data Plugin (v5)
*
* @author Jackkel Dragon
*
* @param Persistent Switches
* @desc The ID of the persistent switches. Formatting example: 1-3,5-6,8,10-11,13
* @Default 1-5
*
* @param Save Switches when Set
* @desc Whether the persistent switches will be saved to the file the moment any switch is set. [true/false]
* @Default true
*
* @param Persistent Variables
* @desc The ID of the persistent variables. Formatting example: 1-3,5-6,8,10-11,13
* @Default 1-5
*
* @param Save Variables when Set
* @desc Whether the persistent variables will be saved to the file the moment any variable is set. [true/false]
* @Default true
*
* @Help
*
* This plugin provides persistent switches and variables that are saved to the
* "Persistent" save file, allowing you to set switches and variables that are
* not tied to a save game. Uses for this could include designing an ending list
* or creating New Game+ elements without requiring the use of a clear save
* file.
*
* The value for each switch/variable in configuration is the switch ID in the
* editor, without any leading zeroes ("10" instead of "0010").
*
* Example: Setting the persistent switches to "1-5,7" will set the switches with
* IDs 1, 2, 3, 4, 5, and 7 to be saved to the persistent data file.
*
* Plugin Command: Persistent Save
* Forces a save of the persistent data file.
*
* Plugin Command: Persistent Load
* Forces the game to load from the persistent data file.
*
* Thanks to "ArcherBanish" for writing the general expression parser
* to allow an undefined number of persistent switches and providing
* the plugin commands.
*
* This plugin is free to use, even in commercial projects. Credit "Jackkel
* Dragon" or "John Cooley".
*
*/
(function() {
var parameters = PluginManager.parameters('JKL_PersistentData');
var _Game_Switches_setValue = Game_Switches.prototype.setValue;
Game_Switches.prototype.setValue = function(switchId, value, save) {
save = typeof save !== 'undefined' ? save : true;
_Game_Switches_setValue.call(this, switchId, value);
if (save && eval(parameters['Save Switches when Set']))
PersistManager.save();
};
var _Game_Variables_setValue = Game_Variables.prototype.setValue;
Game_Variables.prototype.setValue = function(varId, value, save) {
save = typeof save !== 'undefined' ? save : true;
_Game_Variables_setValue.call(this, varId, value);
if (save && eval(parameters['Save Variables when Set']))
PersistManager.save();
};
var _DataManager_createGameObjects = DataManager.createGameObjects;
DataManager.createGameObjects = function() {
_DataManager_createGameObjects();
PersistManager.load();
};
var _StorageManager_localFilePath = StorageManager.localFilePath;
StorageManager.localFilePath = function(savefileId) {
var name;
if (savefileId === "Persistent")
name = StorageManager.localFileDirectoryPath() + "persistent.rpgsave";
else
name = _StorageManager_localFilePath.call(this,savefileId);
return name;
};
var _Scene_Load_onLoadSuccess = Scene_Load.prototype.onLoadSuccess;
Scene_Load.prototype.onLoadSuccess = function() {
_Scene_Load_onLoadSuccess.call(this);
PersistManager.load();
}
//-----------------------------------------------------------------------------
// Persistent Data Manager
//
// The static class that manages the persistent data.
function PersistManager() {
throw new Error('This is a static class');
}
PersistManager.load = function() {
var json;
var persist = {};
try {
json = StorageManager.load("Persistent", json);
} catch (e) {
console.error(e);
}
if (json) {
persist = JSON.parse(json);
}
this.applyData(persist);
};
PersistManager.save = function() {
StorageManager.save("Persistent", JSON.stringify(this.makeData()));
};
PersistManager.makeData = function() {
var persistswexp = parameters['Persistent Switches'];
var switches = XUtil.resolve(persistswexp);
var persistvarexp = parameters['Persistent Variables'];
var variables = XUtil.resolve(persistvarexp);
var persist = {};
persist.switches = [];
persist.variables = [];
for(var x of switches){
persist.switches[x] = $gameSwitches.value(x);
}
for(var y of variables){
persist.variables[y] = $gameVariables.value(y);
}
return persist;
};
PersistManager.applyData = function(persist) {
var persistswexp = parameters['Persistent Switches'];
var switches = XUtil.resolve(persistswexp);
var persistvarexp = parameters['Persistent Variables'];
var variables = XUtil.resolve(persistvarexp);
if(typeof switches !== 'undefined' && typeof persist.switches !== 'undefined'){
for(var x of switches){
if(typeof x !== 'undefined'){
$gameSwitches.setValue(x, persist.switches[x], false);
}
}
}
if(typeof variables !== 'undefined' && typeof persist.variables !== 'undefined'){
for(var y of variables){
if(typeof y !== 'undefined'){
$gameVariables.setValue(y, persist.variables[y], false);
}
}
}
};
PersistManager.readFlag = function(persist, name) {
return !!persist[name];
};
function XUtil() {
throw new Error('This is a static class');
}
XUtil.resolve = function(regex) {
var allsemiexp = regex.split(',');
var semiexp = null;
var semisemiexp = null;
var indexes = new Array();
var curentindex = 0;
for(semiexp of allsemiexp){
semisemiexp = semiexp.split('-');
if(semisemiexp.length > 1){
y = Number(semisemiexp[1]);
for(var x = Number(semisemiexp[0]); x <= y; x++){
indexes[curentindex] = x;
curentindex++;
}
}else{
indexes[curentindex] = Number(semisemiexp[0]);
curentindex++;
}
}
return indexes;
}
var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
_Game_Interpreter_pluginCommand.call(this, command, args);
if (command === 'Persistent') {
switch (args[0]) {
case 'Save':
PersistManager.save(parameters);
break;
case 'Load':
PersistManager.load(parameters);
break;
}
}
}
})();
v4 (Formatting broken from forum changes)
//=============================================================================// JKL_PersistentData.js//=============================================================================/*: * @plugindesc Jackkel's Persistent Switches Plugin (v4) * * @author Jackkel Dragon * * @param Persistent Switches * @desc The ID of the persistent switches. Formatting example: 1-3,5-6,8,10-11,13 * @Default 1-5 * * @param Save Switches when Set * @desc Whether the persistent switches will be saved to the file the moment any switch is set. [true/false] * @Default true * * @Help * * This plugin provides persistent switches that are saved to the * "Persistent" save file, allowing you to set switches that are not tied to a * save game. Uses for this could include designing an ending list or * creating New Game+ elements without requiring the use of a clear save * file. * * The switch numbers in the plugin configuration are for internal use only: * you don't need to remember which switch is assigned to which persistent * slot. The value for each switch in configuration is the switch ID in the * editor, without any leading zeroes ("10" instead of "0010"). * * Example: Setting the persistent switches to "1-5,7" will set the switches with * IDs 1, 2, 3, 4, 5, and 7 to be saved to the persistent data file. * * Plugin Command: Persistent Save * Forces a save of the persistent data file. * * Plugin Command: Persistent Load * Forces the game to load from the persistent data file. * * Thanks to "ArcherBanish" for writing the general expression parser * to allow an undefined number of persistent switches and providing * the plugin commands. * * This plugin is free to use, even in commercial projects. Credit "Jackkel * Dragon" or "John Cooley". * */(function() {var parameters = PluginManager.parameters('JKL_PersistentData');var _Game_Switches_setValue = Game_Switches.prototype.setValue;Game_Switches.prototype.setValue = function(switchId, value, save) { save = typeof save !== 'undefined' ? save : true; _Game_Switches_setValue.call(this, switchId, value); if (save && eval(parameters['Save Switches when Set'])) PersistManager.save(parameters);};var _DataManager_createGameObjects = DataManager.createGameObjects;DataManager.createGameObjects = function() { _DataManager_createGameObjects(); PersistManager.load(parameters);};var _StorageManager_localFilePath = StorageManager.localFilePath;StorageManager.localFilePath = function(savefileId) { var name; if (savefileId === "Persistent") name = StorageManager.localFileDirectoryPath() + "persistent.rpgsave"; else name = _StorageManager_localFilePath.call(this,savefileId); return name;};var _Scene_Load_onLoadSuccess = Scene_Load.prototype.onLoadSuccess;Scene_Load.prototype.onLoadSuccess = function() { _Scene_Load_onLoadSuccess.call(this); PersistManager.load(parameters);} //-----------------------------------------------------------------------------// Persistent Data Manager//// The static class that manages the persistent data.function PersistManager() { throw new Error('This is a static class');}PersistManager.load = function(parameters) { var json; var persist = {}; try { json = StorageManager.load("Persistent", json); } catch (e) { console.error(e); } if (json) { persist = JSON.parse(json); } this.applyData(persist, parameters);};PersistManager.save = function(parameters) { StorageManager.save("Persistent", JSON.stringify(this.makeData(parameters)));};PersistManager.makeData = function(parameters) { var persistexp = parameters['Persistent Switches']; var switches = XUtil.resolve(persistexp); var persist = []; for(var x of switches){ persist[x] = $gameSwitches.value(x); } return persist;};PersistManager.applyData = function(persist, parameters) { var persistexp = parameters['Persistent Switches']; var switches = XUtil.resolve(persistexp); for(var x of switches){ $gameSwitches.setValue(x, persist[x], false); }};PersistManager.readFlag = function(persist, name) { return !!persist[name];};function XUtil() { throw new Error('This is a static class');}XUtil.resolve = function(regex) { var allsemiexp = regex.split(','); var semiexp = null; var semisemiexp = null; var indexes = new Array(); var curentindex = 0; for(semiexp of allsemiexp){ semisemiexp = semiexp.split('-'); if(semisemiexp.length > 1){ y = Number(semisemiexp[1]); for(var x = Number(semisemiexp[0]); x <= y; x++){ indexes[curentindex] = x; curentindex++; } }else{ indexes[curentindex] = Number(semisemiexp[0]); curentindex++; } } return indexes;}var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;Game_Interpreter.prototype.pluginCommand = function(command, args) { _Game_Interpreter_pluginCommand.call(this, command, args); if (command === 'Persistent') { switch (args[0]) { case 'Save': PersistManager.save(parameters); break; case 'Load': PersistManager.load(parameters); break; } }}})();
v3 (Formatting broken from forum changes)
//=============================================================================// JKL_PersistentData.js//=============================================================================/*: * @plugindesc Jackkel's Persistent Switches Plugin (v3) * * @author Jackkel Dragon * * @param Persistent Switch #01 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #02 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #03 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #04 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #05 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #06 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #07 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #08 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #09 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #10 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #11 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #12 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #13 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #14 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #15 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #16 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #17 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #18 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #19 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #20 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @Help * * This plugin provides up to 20 persistent switches that are saved to the * "Persistent" save file, allowing you to set switches that are not tied to a * save game. Uses for this could include designing an ending list or * creating New Game+ elements without requiring the use of a clear save * file. * * The switch numbers in the plugin configuration are for internal use only: * you don't need to remember which switch is assigned to which persistent * slot. The value for each switch in configuration is the switch ID in the * editor. * * Example: Setting the first persistent switch to be 15 will cause the switch * with ID 15 to be saved to the persistent data whenever it is changed. * * Note: If you don't need all the switches, you *should* be able to set the * plugin configuration for those switches to '-1'. (Needs more testing.) * * This plugin is free to use, even in commercial projects. Credit "Jackkel * Dragon" or "John Cooley". * */(function() {var parameters = PluginManager.parameters('JKL_PersistentData'); var _Game_Switches_setValue = Game_Switches.prototype.setValue;Game_Switches.prototype.setValue = function(switchId, value, save) { save = typeof save !== 'undefined' ? save : true; _Game_Switches_setValue.call(this, switchId, value); if (save) PersistManager.save(parameters);};var _Scene_Title_create = Scene_Title.prototype.create;Scene_Title.prototype.create = function() { PersistManager.load(parameters); _Scene_Title_create.call(this);};var _DataManager_createGameObjects = DataManager.createGameObjects;DataManager.createGameObjects = function() { _DataManager_createGameObjects(); PersistManager.load(parameters);};var _StorageManager_localFilePath = StorageManager.localFilePath;StorageManager.localFilePath = function(savefileId) { var name; if (savefileId === "Persistent") name = StorageManager.localFileDirectoryPath() + "persistent.rpgsave"; else name = _StorageManager_localFilePath.call(this,savefileId); return name;};var _Scene_Load_onLoadSuccess = Scene_Load.prototype.onLoadSuccess;Scene_Load.prototype.onLoadSuccess = function() { _Scene_Load_onLoadSuccess.call(this); PersistManager.load(parameters);};//-----------------------------------------------------------------------------// Persistent Data Manager//// The static class that manages the persistent data.function PersistManager() { throw new Error('This is a static class');}PersistManager.load = function(parameters) { var json; var persist = {}; try { json = StorageManager.load("Persistent", json); } catch (e) { console.error(e); } if (json) { persist = JSON.parse(json); } this.applyData(persist, parameters);};PersistManager.save = function(parameters) { StorageManager.save("Persistent", JSON.stringify(this.makeData(parameters))); };PersistManager.makeData = function(parameters) { var persist = {}; persist.Persist01 = $gameSwitches.value(parameters['Persistent Switch #01']); persist.Persist02 = $gameSwitches.value(parameters['Persistent Switch #02']); persist.Persist03 = $gameSwitches.value(parameters['Persistent Switch #03']); persist.Persist04 = $gameSwitches.value(parameters['Persistent Switch #04']); persist.Persist05 = $gameSwitches.value(parameters['Persistent Switch #05']); persist.Persist06 = $gameSwitches.value(parameters['Persistent Switch #06']); persist.Persist07 = $gameSwitches.value(parameters['Persistent Switch #07']); persist.Persist08 = $gameSwitches.value(parameters['Persistent Switch #08']); persist.Persist09 = $gameSwitches.value(parameters['Persistent Switch #09']); persist.Persist10 = $gameSwitches.value(parameters['Persistent Switch #10']); persist.Persist11 = $gameSwitches.value(parameters['Persistent Switch #11']); persist.Persist12 = $gameSwitches.value(parameters['Persistent Switch #12']); persist.Persist13 = $gameSwitches.value(parameters['Persistent Switch #13']); persist.Persist14 = $gameSwitches.value(parameters['Persistent Switch #14']); persist.Persist15 = $gameSwitches.value(parameters['Persistent Switch #15']); persist.Persist16 = $gameSwitches.value(parameters['Persistent Switch #16']); persist.Persist17 = $gameSwitches.value(parameters['Persistent Switch #17']); persist.Persist18 = $gameSwitches.value(parameters['Persistent Switch #18']); persist.Persist19 = $gameSwitches.value(parameters['Persistent Switch #19']); persist.Persist20 = $gameSwitches.value(parameters['Persistent Switch #20']); return persist;};PersistManager.applyData = function(persist, parameters) { // read from the file this.Persist01 = this.readFlag(persist, 'Persist01'); this.Persist02 = this.readFlag(persist, 'Persist02'); this.Persist03 = this.readFlag(persist, 'Persist03'); this.Persist04 = this.readFlag(persist, 'Persist04'); this.Persist05 = this.readFlag(persist, 'Persist05'); this.Persist06 = this.readFlag(persist, 'Persist06'); this.Persist07 = this.readFlag(persist, 'Persist07'); this.Persist08 = this.readFlag(persist, 'Persist08'); this.Persist09 = this.readFlag(persist, 'Persist09'); this.Persist10 = this.readFlag(persist, 'Persist10'); this.Persist11 = this.readFlag(persist, 'Persist11'); this.Persist12 = this.readFlag(persist, 'Persist12'); this.Persist13 = this.readFlag(persist, 'Persist13'); this.Persist14 = this.readFlag(persist, 'Persist14'); this.Persist15 = this.readFlag(persist, 'Persist15'); this.Persist16 = this.readFlag(persist, 'Persist16'); this.Persist17 = this.readFlag(persist, 'Persist17'); this.Persist18 = this.readFlag(persist, 'Persist18'); this.Persist19 = this.readFlag(persist, 'Persist19'); this.Persist20 = this.readFlag(persist, 'Persist20'); // apply to the game itself $gameSwitches.setValue(parameters['Persistent Switch #01'], this.Persist01, false); $gameSwitches.setValue(parameters['Persistent Switch #02'], this.Persist02, false); $gameSwitches.setValue(parameters['Persistent Switch #03'], this.Persist03, false); $gameSwitches.setValue(parameters['Persistent Switch #04'], this.Persist04, false); $gameSwitches.setValue(parameters['Persistent Switch #05'], this.Persist05, false); $gameSwitches.setValue(parameters['Persistent Switch #06'], this.Persist06, false); $gameSwitches.setValue(parameters['Persistent Switch #07'], this.Persist07, false); $gameSwitches.setValue(parameters['Persistent Switch #08'], this.Persist08, false); $gameSwitches.setValue(parameters['Persistent Switch #09'], this.Persist09, false); $gameSwitches.setValue(parameters['Persistent Switch #10'], this.Persist10, false); $gameSwitches.setValue(parameters['Persistent Switch #11'], this.Persist11, false); $gameSwitches.setValue(parameters['Persistent Switch #12'], this.Persist12, false); $gameSwitches.setValue(parameters['Persistent Switch #13'], this.Persist13, false); $gameSwitches.setValue(parameters['Persistent Switch #14'], this.Persist14, false); $gameSwitches.setValue(parameters['Persistent Switch #15'], this.Persist15, false); $gameSwitches.setValue(parameters['Persistent Switch #16'], this.Persist16, false); $gameSwitches.setValue(parameters['Persistent Switch #17'], this.Persist17, false); $gameSwitches.setValue(parameters['Persistent Switch #18'], this.Persist18, false); $gameSwitches.setValue(parameters['Persistent Switch #19'], this.Persist19, false); $gameSwitches.setValue(parameters['Persistent Switch #20'], this.Persist20, false);};PersistManager.readFlag = function(persist, name) { return !!persist[name];};})();
v2 (Formatting broken from forum changes)
//=============================================================================// JKL_PersistentData.js//=============================================================================/*: * @plugindesc Jackkel's Persistent Switches Plugin (v2) * * @author Jackkel Dragon * * @param Persistent Switch #01 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #02 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #03 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #04 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #05 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #06 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #07 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #08 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #09 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #10 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #11 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #12 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #13 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #14 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #15 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #16 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #17 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #18 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #19 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @param Persistent Switch #20 * @desc The ID of the persistent switch. (-1 = unused) * @Default -1 * * @Help * * This plugin provides up to 20 persistent switches that are saved to the * "Persistent" save file, allowing you to set switches that are not tied to a * save game. Uses for this could include designing an ending list or * creating New Game+ elements without requiring the use of a clear save * file. * * The switch numbers in the plugin configuration are for internal use only: * you don't need to remember which switch is assigned to which persistent * slot. The value for each switch in configuration is the switch ID in the * editor. * * Example: Setting the first persistent switch to be 15 will cause the switch * with ID 15 to be saved to the persistent data whenever it is changed. * * Note: If you don't need all the switches, you *should* be able to set the * plugin configuration for those switches to '-1'. (Needs more testing.) * * This plugin is free to use, even in commercial projects. Credit "Jackkel *Dragon" or "John Cooley". * */(function() { var parameters = PluginManager.parameters('JKL_PersistentData'); var _Game_Switches_setValue = Game_Switches.prototype.setValue;Game_Switches.prototype.setValue = function(switchId, value) { _Game_Switches_setValue.call(this, switchId, value); PersistManager.save(parameters);};var _Scene_Title_create = Scene_Title.prototype.create;Scene_Title.prototype.create = function() { PersistManager.load(parameters); _Scene_Title_create.call(this);};var _DataManager_createGameObjects = DataManager.createGameObjects;DataManager.createGameObjects = function() { _DataManager_createGameObjects(); PersistManager.load(parameters);};var _StorageManager_localFilePath = StorageManager.localFilePath;StorageManager.localFilePath = function(savefileId) { var name; if (savefileId === "Persistent") name = StorageManager.localFileDirectoryPath() + "persistent.rpgsave"; else name = _StorageManager_localFilePath.call(this,savefileId); return name;};var _Scene_Load_onLoadSuccess = Scene_Load.prototype.onLoadSuccess;Scene_Load.prototype.onLoadSuccess = function() { _Scene_Load_onLoadSuccess.call(this); PersistManager.load(parameters);};//-----------------------------------------------------------------------------// Persistent Data Manager//// The static class that manages the persistent data.function PersistManager() { throw new Error('This is a static class');}PersistManager.load = function(parameters) { var json; var persist = {}; try { json = StorageManager.load("Persistent", json); } catch (e) { console.error(e); } if (json) { persist = JSON.parse(json); } this.applyData(persist, parameters);};PersistManager.save = function(parameters) { StorageManager.save("Persistent", JSON.stringify(this.makeData(parameters))); };PersistManager.makeData = function(parameters) { var persist = {}; persist.Persist01 = $gameSwitches.value(parameters['Persistent Switch #01']); persist.Persist02 = $gameSwitches.value(parameters['Persistent Switch #02']); persist.Persist03 = $gameSwitches.value(parameters['Persistent Switch #03']); persist.Persist04 = $gameSwitches.value(parameters['Persistent Switch #04']); persist.Persist05 = $gameSwitches.value(parameters['Persistent Switch #05']); persist.Persist06 = $gameSwitches.value(parameters['Persistent Switch #06']); persist.Persist07 = $gameSwitches.value(parameters['Persistent Switch #07']); persist.Persist08 = $gameSwitches.value(parameters['Persistent Switch #08']); persist.Persist09 = $gameSwitches.value(parameters['Persistent Switch #09']); persist.Persist10 = $gameSwitches.value(parameters['Persistent Switch #10']); persist.Persist11 = $gameSwitches.value(parameters['Persistent Switch #11']); persist.Persist12 = $gameSwitches.value(parameters['Persistent Switch #12']); persist.Persist13 = $gameSwitches.value(parameters['Persistent Switch #13']); persist.Persist14 = $gameSwitches.value(parameters['Persistent Switch #14']); persist.Persist15 = $gameSwitches.value(parameters['Persistent Switch #15']); persist.Persist16 = $gameSwitches.value(parameters['Persistent Switch #16']); persist.Persist17 = $gameSwitches.value(parameters['Persistent Switch #17']); persist.Persist18 = $gameSwitches.value(parameters['Persistent Switch #18']); persist.Persist19 = $gameSwitches.value(parameters['Persistent Switch #19']); persist.Persist20 = $gameSwitches.value(parameters['Persistent Switch #20']); return persist;};PersistManager.applyData = function(persist, parameters) { // read from the file this.Persist01 = this.readFlag(persist, 'Persist01'); this.Persist02 = this.readFlag(persist, 'Persist02'); this.Persist03 = this.readFlag(persist, 'Persist03'); this.Persist04 = this.readFlag(persist, 'Persist04'); this.Persist05 = this.readFlag(persist, 'Persist05'); this.Persist06 = this.readFlag(persist, 'Persist06'); this.Persist07 = this.readFlag(persist, 'Persist07'); this.Persist08 = this.readFlag(persist, 'Persist08'); this.Persist09 = this.readFlag(persist, 'Persist09'); this.Persist10 = this.readFlag(persist, 'Persist10'); this.Persist11 = this.readFlag(persist, 'Persist11'); this.Persist12 = this.readFlag(persist, 'Persist12'); this.Persist13 = this.readFlag(persist, 'Persist13'); this.Persist14 = this.readFlag(persist, 'Persist14'); this.Persist15 = this.readFlag(persist, 'Persist15'); this.Persist16 = this.readFlag(persist, 'Persist16'); this.Persist17 = this.readFlag(persist, 'Persist17'); this.Persist18 = this.readFlag(persist, 'Persist18'); this.Persist19 = this.readFlag(persist, 'Persist19'); this.Persist20 = this.readFlag(persist, 'Persist20'); // apply to the game itself $gameSwitches.setValue(parameters['Persistent Switch #01'], this.Persist01); $gameSwitches.setValue(parameters['Persistent Switch #02'], this.Persist02); $gameSwitches.setValue(parameters['Persistent Switch #03'], this.Persist03); $gameSwitches.setValue(parameters['Persistent Switch #04'], this.Persist04); $gameSwitches.setValue(parameters['Persistent Switch #05'], this.Persist05); $gameSwitches.setValue(parameters['Persistent Switch #06'], this.Persist06); $gameSwitches.setValue(parameters['Persistent Switch #07'], this.Persist07); $gameSwitches.setValue(parameters['Persistent Switch #08'], this.Persist08); $gameSwitches.setValue(parameters['Persistent Switch #09'], this.Persist09); $gameSwitches.setValue(parameters['Persistent Switch #10'], this.Persist10); $gameSwitches.setValue(parameters['Persistent Switch #11'], this.Persist11); $gameSwitches.setValue(parameters['Persistent Switch #12'],this.Persist12); $gameSwitches.setValue(parameters['Persistent Switch #13'], this.Persist13); $gameSwitches.setValue(parameters['Persistent Switch #14'], this.Persist14); $gameSwitches.setValue(parameters['Persistent Switch #15'], this.Persist15); $gameSwitches.setValue(parameters['Persistent Switch #16'], this.Persist16); $gameSwitches.setValue(parameters['Persistent Switch #17'], this.Persist17); $gameSwitches.setValue(parameters['Persistent Switch #18'], this.Persist18); $gameSwitches.setValue(parameters['Persistent Switch #19'], this.Persist19); $gameSwitches.setValue(parameters['Persistent Switch #20'], this.Persist20);};PersistManager.readFlag = function(persist, name) { return !!persist[name];};})();
Potential Hotfix for problems in v5
var _DataManager_createGameObjects = DataManager.createGameObjects;
DataManager.createGameObjects = function() {
_DataManager_createGameObjects();
PersistManager.load();
};
// Changed to:
var _DataManager_createGameObjects = DataManager.createGameObjects;
DataManager.createGameObjects = function() {
_DataManager_createGameObjects.call(this);
PersistManager.load();
};
DataManager.createGameObjects = function() {
_DataManager_createGameObjects();
PersistManager.load();
};
// Changed to:
var _DataManager_createGameObjects = DataManager.createGameObjects;
DataManager.createGameObjects = function() {
_DataManager_createGameObjects.call(this);
PersistManager.load();
};
Credits
ArcherBanish: General expression parser for the persistent switches parameter and the plugin commands.
Terms
Free to use, even for commercial projects. Credit "Jackkel Dragon" or "John Cooley".
Last edited: