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,660
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

image_2021-06-16_153010.png

Why are barrels to difficult? xD I feel like i Barrel...y made it....eh EHHH!? :p
Bluh... glad this present heatwave is coming to a close...
Look what I found, it was my first ABS.

This project was never completed because I had lost the computer where it was stored.
Character Creator for RPGM 2000, VX, XP, & LPC Style Sprites | RPG Maker News #72

Is there any way to get more than 8 enemies in a troop in RMMV or is that limit pretty much hardcoded into the engine?

Forum statistics

Threads
112,277
Messages
1,067,029
Members
145,899
Latest member
noor123
Top