jackken123

Veteran
Veteran
Joined
Aug 24, 2017
Messages
81
Reaction score
8
First Language
Chinese
Primarily Uses
RMMV
Hi,
I got a question about how to load file through js.

Now I have save a file, let's say save file 1.
How can I load this save file 1 by js.

Thank you.
 
Last edited:
Joined
Sep 1, 2017
Messages
105
Reaction score
52
First Language
English
Primarily Uses
RMMV
How do you mean load? Like through JS, the game save file 1 would load?

Bit more info would be needed, like what your plain or purpose with this? the reason, why I ask, is that most people that do request and request it be done through JS can easily be done with Events.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,657
First Language
Czech
Primarily Uses
RMMV
Filemanager.loadFromLocalFile in rpg_managers contains the answer.
 

jackken123

Veteran
Veteran
Joined
Aug 24, 2017
Messages
81
Reaction score
8
First Language
Chinese
Primarily Uses
RMMV
How do you mean load? Like through JS, the game save file 1 would load?

Bit more info would be needed, like what your plain or purpose with this? the reason, why I ask, is that most people that do request and request it be done through JS can easily be done with Events.
Just like in scene load.
You select a file and you'll load.
I want to have a quest, when it fall, it will auto load the file.
Of course, I'll save the file at where I want it to restart.
Not just open the scene load is because I don't want player to choose the file.
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,634
Reaction score
1,452
First Language
French
Primarily Uses
RMMV
You have also a way with nwJS NODE, its easy but it not compatible with Android.
Here the two way you can do, maybe more ?...

XMLHTTPRequest:
PHP:
    DataManager.loadDataFile = function(name, src) { // testter compatible android
    var xhr = new XMLHttpRequest();
    var url = 'data/' + src;
    xhr.open('GET', url);
    xhr.overrideMimeType('application/json');
    xhr.onload = function() {
        if (xhr.status < 400) {
            window[name] = JSON.parse(xhr.responseText);
            DataManager.onLoad(window[name]);
        }
    };
    xhr.onerror = this._mapLoader || function() {
        DataManager._errorUrl = DataManager._errorUrl || url;
    };
    window[name] = null;
    xhr.send();

Node: (it a copy paste from my source , but you need more study with consol.log variable, its more powerfull way, but not work on Android)
PHP:
        if(Utils.isNwjs()){ // if pc or mac linux TODO: ANDROID + loader
        var path = require('path'),
            gameDir = path.dirname(process.mainModule.filename),
            fs = require('fs');
        var valid_JSON = {};
        for (objName in this._aniObj) {
            if (typeof this._aniObj[objName] !== "object") { continue; }; // jumper valide name 'object'
            valid_JSON[objName] = [];
            for (var i = 0, len = this._aniObj[objName].json.length; i < len; i++) {
                var dirFile = this._aniObj[objName].json[i];
                if (fs.existsSync(gameDir + '/' + dirFile + '.json')) {
                    valid_JSON[objName].push(dirFile + '.json');
                    continue;
                };
                for (var num = 0;; num++) {
                    if (fs.existsSync(gameDir + '/' + dirFile + '-' + num + '.json')) {
                        valid_JSON[objName].push(dirFile + '-' + num + '.json');
                    } else { break; };
                };
            };
        };
        for (objName in valid_JSON) {
            Object.defineProperty(this._aniObj[objName], 'valid_JSON', { enumerable: false, configurable: false, value: valid_JSON[objName] });
        };

here a example for get your machine id in windows with open file in a buffer.
Easy for open a file , and read context buffer, this for made a custom keyGen or function evaluation from your saves DATA in JSON or another files extentions.
PHP:
var fs = require('fs');
var path = process.cwd();
var buffer = fs.readFileSync('C:\\Windows\\INF\\machine.inf');
console.log(buffer.toString());
index.php

after you can use a regex if you need read string in the file.
More info:
https://forums.rpgmakerweb.com/index.php?threads/node-js-machineid-solved.81127/#post-753862

In you specific case, you can read all save file and proprety from JSON as string, and use eval("string").
from the regex
 
Last edited:

jackken123

Veteran
Veteran
Joined
Aug 24, 2017
Messages
81
Reaction score
8
First Language
Chinese
Primarily Uses
RMMV
You have also a way with nwJS NODE, its easy but it not compatible with Android.
Here the two way you can do, maybe more ?...

XMLHTTPRequest:
PHP:
    DataManager.loadDataFile = function(name, src) { // testter compatible android
    var xhr = new XMLHttpRequest();
    var url = 'data/' + src;
    xhr.open('GET', url);
    xhr.overrideMimeType('application/json');
    xhr.onload = function() {
        if (xhr.status < 400) {
            window[name] = JSON.parse(xhr.responseText);
            DataManager.onLoad(window[name]);
        }
    };
    xhr.onerror = this._mapLoader || function() {
        DataManager._errorUrl = DataManager._errorUrl || url;
    };
    window[name] = null;
    xhr.send();

Node: (it a copy paste from my source , but you need more study with consol.log variable, its more powerfull way, but not work on Android)
PHP:
        if(Utils.isNwjs()){ // if pc or mac linux TODO: ANDROID + loader
        var path = require('path'),
            gameDir = path.dirname(process.mainModule.filename),
            fs = require('fs');
        var valid_JSON = {};
        for (objName in this._aniObj) {
            if (typeof this._aniObj[objName] !== "object") { continue; }; // jumper valide name 'object'
            valid_JSON[objName] = [];
            for (var i = 0, len = this._aniObj[objName].json.length; i < len; i++) {
                var dirFile = this._aniObj[objName].json[i];
                if (fs.existsSync(gameDir + '/' + dirFile + '.json')) {
                    valid_JSON[objName].push(dirFile + '.json');
                    continue;
                };
                for (var num = 0;; num++) {
                    if (fs.existsSync(gameDir + '/' + dirFile + '-' + num + '.json')) {
                        valid_JSON[objName].push(dirFile + '-' + num + '.json');
                    } else { break; };
                };
            };
        };
        for (objName in valid_JSON) {
            Object.defineProperty(this._aniObj[objName], 'valid_JSON', { enumerable: false, configurable: false, value: valid_JSON[objName] });
        };

here a example for get your machine id in windows with open file in a buffer.
Easy for open a file , and read context buffer, this for made a custom keyGen or function evaluation from your saves DATA in JSON or another files extentions.
PHP:
var fs = require('fs');
var path = process.cwd();
var buffer = fs.readFileSync('C:\\Windows\\INF\\machine.inf');
console.log(buffer.toString());
index.php

after you can use a regex if you need read string in the file.
More info:
https://forums.rpgmakerweb.com/index.php?threads/node-js-machineid-solved.81127/#post-753862

In you specific case, you can read all save file and proprety from JSON as string, and use eval("string").
from the regex
Great!!
Thank you so much.
 

jackken123

Veteran
Veteran
Joined
Aug 24, 2017
Messages
81
Reaction score
8
First Language
Chinese
Primarily Uses
RMMV
I did it with this.

Code:
DataManager.loadGame(id);
$gamePlayer.reserveTransfer($gameMap.mapId(), $gamePlayer.x, $gamePlayer.y);
$gamePlayer.requestMapReload();
SceneManager.goto(Scene_Map);
$gameSystem.onAfterLoad();
 

Latest Threads

Latest Profile Posts

here's another RPG Maker remake idea: "Plumbers Don't Wear Ties". I'll salute to whomever does this
I won't finish it today, I only will have time to work on that next Saturday, what a shame... :(
I made something for @LittenDev [as he requested]
It's been a weird while. I've been so torn down that even playing video games has been something I avoided. But I shouldn't forget two things. One, I love RPG Maker for a reason. Two, only way to eat an elephant is a bite at a time.

Forum statistics

Threads
111,388
Messages
1,060,739
Members
144,731
Latest member
ariOwl
Top