查看: 4488|回复: 5

[已经解决] 请教在不保存游戏的情况下也会保存下开关和变量的方法

[复制链接]
梦石
0
星屑
50
在线时间
78 小时
注册时间
2015-12-5
回帖
7
发表于 2016-2-9 00:54:56 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
http://forums.rpgmakerweb.com/in ... ersistent-switches/
↑之前看到了这个,但是似乎只能在保存之后使用,但是因为窝所需要做的“死亡结局”在死亡后是不能保存的呀~会回到标题画面,所以如何在死亡后保存下这个开关呢?
请教一下。(以及上面这个js窝按照作者说的注意事项操作了但是貌似依旧不成功,似乎是因为我的开关和变量自带编号是0001,前面有0,作者说开关和变量是没有前面0的。可是前面的0怎么取消我也不懂……(捂脸
简单来说就是希望可以做死亡结局鉴赏,毕竟是希望做一个坑人向的游戏。
↑不知道自己弱渣的语文有没有表达清楚意思……简单来说就是死亡后会回标题画面,然而如何记录这样:增加了一个死亡数、打开了一个死亡结局开关。
以上,非常感谢可以看完在下羸弱的表达。。。。
以及再次非常感谢可以为在下答疑解惑的人。(←重要的是这人刚接触这玩意并不会编程还在纠结QAQ……)

点评

有個Plugin可在死亡及save時自動保存一些特定的変数/開関,也可手動S/L★共有セーブデータプラグイン★http://utakata-no-yume.net/gallery/plugin/tkmv/cmn_save/  发表于 2016-2-15 16:16
梦石
0
星屑
55
在线时间
388 小时
注册时间
2009-8-4
回帖
212
发表于 2016-2-9 01:05:05 | 显示全部楼层
本帖最后由 andrewx 于 2016-2-9 01:07 编辑

插件说明里有写:使用如下插件指令:
Persistent Save 强制保存你定义的变量/开关状态
Persistent Load 强制读取覆盖你定义的变量/开关状态
如果不生效尝试删除这个插件生成的文件后再试
另作者的意思是写开关变量列表时候不要在前面补零。。

评分

参与人数 1星屑 +266 收起 理由
余烬之中 + 266 认可答案

查看全部评分

回复

使用道具 举报

梦石
0
星屑
50
在线时间
78 小时
注册时间
2015-12-5
回帖
7
 楼主| 发表于 2016-2-10 03:33:56 | 显示全部楼层
andrewx 发表于 2016-2-9 01:05
插件说明里有写:使用如下插件指令:
Persistent Save 强制保存你定义的变量/开关状态
Persistent Load 强 ...

非常感谢QAQ,在下因为在外国因为经常无法打开网页问题总是不能及时的回复实在抱歉!
再次感谢您对在下的指导!QAQ果然还是在下的英语不过关啊……
回复

使用道具 举报

梦石
0
星屑
50
在线时间
78 小时
注册时间
2015-12-5
回帖
7
 楼主| 发表于 2016-2-12 17:07:11 | 显示全部楼层
本帖最后由 daxingdaiyu 于 2016-2-12 17:08 编辑
andrewx 发表于 2016-2-9 01:05
插件说明里有写:使用如下插件指令:
Persistent Save 强制保存你定义的变量/开关状态
Persistent Load 强 ...


弱炸.png 弱炸2.png 弱炸3.png
实在抱歉还要再打搅您……这是在下测试用的内容。
文件名和开关以及各种事情貌似都注意了,然而怎么实验都不成功……
删除了所有的存档并且文件也删除了重新按照步骤弄了一个,然而问题依旧……
请问是在下弱鸡的指令步骤出问题了嘛QAQ……
再次感谢您对在下的解答

(附:简单来说就是打开游戏自动执行这个程序,选择YES后会GO,然后再次点开始游戏应该就会看到那个实验终了才对?但是一直无法看到……)
回复

使用道具 举报

梦石
0
星屑
55
在线时间
388 小时
注册时间
2009-8-4
回帖
212
发表于 2016-2-12 19:58:03 | 显示全部楼层
本帖最后由 andrewx 于 2016-2-12 20:07 编辑

我去看了新版这个插件,不是很懂这个作者,为了简化帖子里删去了所有换行,然而还用着单行注释,因此直接复制保存的话所有代码其实都被注释掉了...明明之前的某版本还一切正常,也可能是RMweb论坛改版产生的问题。
我把现在v5的代码格式整理了下,测试了一下能正常保存变量,不保证无错,请自行测试:
代码

  1. //=============================================================================
  2. // JKL_PersistentData.js
  3. //=============================================================================
  4. /*:
  5. * @plugindesc Jackkel's Persistent Data Plugin (v5)
  6. * @author Jackkel Dragon
  7. *
  8. * @param Persistent Switches
  9. * @desc The ID of the persistent switches. Formatting example: 1-3,5-6,8,10-11,13
  10. * @default 1-5
  11. *
  12. * @param Save Switches when Set
  13. * @desc Whether the persistent switches will be saved to the file the moment any switch is set. [true/false]
  14. * @default true
  15. *
  16. * @param Persistent Variables
  17. * @desc The ID of the persistent variables. Formatting example: 1-3,5-6,8,10-11,13
  18. * @default 1-5
  19. *
  20. * @param Save Variables when Set
  21. * @desc Whether the persistent variables will be saved to the file the moment any variable is set. [true/false]
  22. * @default true
  23. *
  24. * @help
  25. * This plugin provides persistent switches and variables that are saved to the
  26. * "Persistent" save file, allowing you to set switches and variables that are
  27. * not tied to a save game. Uses for this could include designing an ending list
  28. * or creating New Game+ elements without requiring the use of a clear save file.
  29. *
  30. * The value for each switch/variable in configuration is the switch ID in the
  31. * editor, without any leading zeroes ("10" instead of "0010").
  32. *
  33. * Example: Setting the persistent switches to "1-5,7" will set the switches with
  34. * IDs 1, 2, 3, 4, 5, and 7 to be saved to the persistent data file.
  35. *
  36. * Plugin Command: Persistent Save
  37. * Forces a save of the persistent data file.
  38. *
  39. * Plugin Command: Persistent Load
  40. * Forces the game to load from the persistent data file.
  41. *
  42. * Thanks to "ArcherBanish" for writing the general expression parser
  43. * to allow an undefined number of persistent switches and providing
  44. * the plugin commands.
  45. *
  46. * This plugin is free to use, even in commercial projects. Credit "Jackkel * Dragon" or "John Cooley".
  47. *
  48. */
  49. (function() {
  50.     var parameters = PluginManager.parameters('JKL_PersistentData');
  51.     var _Game_Switches_setValue = Game_Switches.prototype.setValue;
  52.     Game_Switches.prototype.setValue = function(switchId, value, save) {
  53.         save = typeof save !== 'undefined' ? save : true;
  54.         _Game_Switches_setValue.call(this, switchId, value);
  55.         if (save && eval(parameters['Save Switches when Set'])) PersistManager.save();
  56.     };
  57.     var _Game_Variables_setValue = Game_Variables.prototype.setValue;
  58.     Game_Variables.prototype.setValue = function(varId, value, save) {
  59.         save = typeof save !== 'undefined' ? save : true;
  60.         _Game_Variables_setValue.call(this, varId, value);
  61.         if (save && eval(parameters['Save Variables when Set'])) PersistManager.save();
  62.     };
  63.     var _DataManager_createGameObjects = DataManager.createGameObjects;
  64.     DataManager.createGameObjects = function() {
  65.         _DataManager_createGameObjects();
  66.         PersistManager.load();
  67.     };
  68.     var _StorageManager_localFilePath = StorageManager.localFilePath;
  69.     StorageManager.localFilePath = function(savefileId) {
  70.         var name;
  71.         if (savefileId === "Persistent") name = StorageManager.localFileDirectoryPath() + "persistent.rpgsave";
  72.         else name = _StorageManager_localFilePath.call(this, savefileId);
  73.         return name;
  74.     };
  75.     var _Scene_Load_onLoadSuccess = Scene_Load.prototype.onLoadSuccess;
  76.     Scene_Load.prototype.onLoadSuccess = function() {
  77.             _Scene_Load_onLoadSuccess.call(this);
  78.             PersistManager.load();
  79.         }
  80.     //-----------------------------------------------------------------------------
  81.     // Persistent Data Manager
  82.     // The static class that manages the persistent data.
  83.     function PersistManager() {
  84.         throw new Error('This is a static class');
  85.     }
  86.     PersistManager.load = function() {
  87.         var json;
  88.         var persist = {};
  89.         try {
  90.             json = StorageManager.load("Persistent", json);
  91.         } catch (e) {
  92.             console.error(e);
  93.         }
  94.         if (json) {
  95.             persist = JSON.parse(json);
  96.         }
  97.         this.applyData(persist);
  98.     };
  99.     PersistManager.save = function() {
  100.         StorageManager.save("Persistent", JSON.stringify(this.makeData()));
  101.     };
  102.     PersistManager.makeData = function() {
  103.         var persistswexp = parameters['Persistent Switches'];
  104.         var switches = XUtil.resolve(persistswexp);
  105.         var persistvarexp = parameters['Persistent Variables'];
  106.         var variables = XUtil.resolve(persistvarexp);
  107.         var persist = {};
  108.         persist.switches = [];
  109.         persist.variables = [];
  110.         for (var x of switches) {
  111.             persist.switches[x] = $gameSwitches.value(x);
  112.         }
  113.         for (var y of variables) {
  114.             persist.variables[y] = $gameVariables.value(y);
  115.         }
  116.         return persist;
  117.     };
  118.     PersistManager.applyData = function(persist) {
  119.         var persistswexp = parameters['Persistent Switches'];
  120.         var switches = XUtil.resolve(persistswexp);
  121.         var persistvarexp = parameters['Persistent Variables'];
  122.         var variables = XUtil.resolve(persistvarexp);
  123.         if (typeof switches !== 'undefined' && typeof persist.switches !== 'undefined') {
  124.             for (var x of switches) {
  125.                 if (typeof x !== 'undefined') {
  126.                     $gameSwitches.setValue(x, persist.switches[x], false);
  127.                 }
  128.             }
  129.         }
  130.         if (typeof variables !== 'undefined' && typeof persist.variables !== 'undefined') {
  131.             for (var y of variables) {
  132.                 if (typeof y !== 'undefined') {
  133.                     $gameVariables.setValue(y, persist.variables[y], false);
  134.                 }
  135.             }
  136.         }
  137.     };
  138.     PersistManager.readFlag = function(persist, name) {
  139.         return !!persist[name];
  140.     };

  141.     function XUtil() {
  142.         throw new Error('This is a static class');
  143.     }
  144.     XUtil.resolve = function(regex) {
  145.         var allsemiexp = regex.split(',');
  146.         var semiexp = null;
  147.         var semisemiexp = null;
  148.         var indexes = new Array();
  149.         var curentindex = 0;
  150.         for (semiexp of allsemiexp) {
  151.             semisemiexp = semiexp.split('-');
  152.             if (semisemiexp.length > 1) {
  153.                 y = Number(semisemiexp[1]);
  154.                 for (var x = Number(semisemiexp[0]); x <= y; x++) {
  155.                     indexes[curentindex] = x;
  156.                     curentindex++;
  157.                 }
  158.             } else {
  159.                 indexes[curentindex] = Number(semisemiexp[0]);
  160.                 curentindex++;
  161.             }
  162.         }
  163.         return indexes;
  164.     }
  165.     var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  166.     Game_Interpreter.prototype.pluginCommand = function(command, args) {
  167.         _Game_Interpreter_pluginCommand.call(this, command, args);
  168.         if (command === 'Persistent') {
  169.             switch (args[0]) {
  170.                 case 'Save':
  171.                     PersistManager.save(parameters);
  172.                     break;
  173.                 case 'Load':
  174.                     PersistManager.load(parameters);
  175.                     break;
  176.             }
  177.         }
  178.     }
  179. })();
复制代码



另:新开游戏和读取游戏的时候你设定的开关变量都会被替换为已保存的状态。
插件里设定两项为true的话游戏内只要修改了变量/开关状态,就会自动保存下来,所以一般情况应该不需要用插件指令。
回复

使用道具 举报

梦石
0
星屑
50
在线时间
78 小时
注册时间
2015-12-5
回帖
7
 楼主| 发表于 2016-2-13 17:35:57 | 显示全部楼层
andrewx 发表于 2016-2-12 19:58
我去看了新版这个插件,不是很懂这个作者,为了简化帖子里删去了所有换行,然而还用着单行注释,因此直接复 ...

QAQ!!
终于……终于!!成功了QAQ!!!!
万分感谢!!!真的实在是太感谢了QAQ!!!!!
您又如此费心的把东西一行一行排好,真是不知道如何感谢您才是QAQ!!!
总之,真是太感谢了QAQ……终于解决了一个长时间困扰在下的问题QAQ……
在下之后一定会继续努力的!!!

点评

我也就给注释换了行,代码格式都是自动整理出来的。加油咯  发表于 2016-2-13 18:30
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部