查看: 4438|回复: 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的代码格式整理了下,测试了一下能正常保存变量,不保证无错,请自行测试:
代码
[pre lang="javascript" line="1" file="JKL_PersistentData.js"]
//=============================================================================
// 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;
            }
        }
    }
})();[/pre]


另:新开游戏和读取游戏的时候你设定的开关变量都会被替换为已保存的状态。
插件里设定两项为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.

在本版发帖返回顶部