RPG Maker MV

RPG Maker MV

Uho i Gira Jul 22, 2019 @ 2:04pm
Conditional branch for the file.
I don't much know in scripts. So can anyone tell which a script for conditional branch that will check a file in the game folder?
For exmaple I have monika.txt, and I wanna do different paths if file will be in folder or not. What I should write in the script line? I will be grateful!
Sorry for English -_-'
< >
Showing 1-3 of 3 comments
Sileka Jul 22, 2019 @ 3:00pm 
Not sure if it is what you are looking for, but I stumbled upon this;

Was a question about making a txt file and checking for a file's existence.
var path = require('path');
var base = path.dirname(process.mainModule.filename);
var fs = require('fs');
var fileText = "First line \nSecond line";
fs.writeFileSync(base + "/test.txt", fileText);

(Located: https://www.reddit.com/r/RPGMaker/comments/8ir3jd/generating_txt_files_and_checking_for_file/)

While the original question was for VXAce, someone in the comments asked if something similar could be done for MV. (The above code was in response to that.)

Also, If you are not comfortable with your English, it never hurts to also type the question/statement/request in your native language.
Last edited by Sileka; Jul 22, 2019 @ 3:00pm
Uho i Gira Jul 22, 2019 @ 4:53pm 
Not really what I want, but I found the solution:
var fs = require('fs'); if(fs.existsSync("test.txt")) { // The file exist } else { // The file does not exist }
the game will check test.txt file in game folder.
Last edited by Uho i Gira; Jul 22, 2019 @ 4:55pm
Caethyril Jul 23, 2019 @ 2:40am 
Note that this requires access to the filesystem library, thus is only applicable for NW.js deployments (platform-specific), i.e. it will not work for web deployment. If you want to write to files as well, you'll need NW.js, since HTML generally has read-only privileges.

An alternative is XMLHttpRequest, but that is typically used asynchronously, i.e. it'll need "load" and "error" functions to execute when the reply is received. Example:
var xhr = new XMLHttpRequest(); var url = 'test.txt'; xhr.open('HEAD', url); xhr.onload = function() { console.info('file exists!'); }; xhr.onerror = function() { console.info('file not found'); }; xhr.send();
More info can be found here: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
Last edited by Caethyril; Jul 23, 2019 @ 7:19am
< >
Showing 1-3 of 3 comments
Per page: 1530 50