- Joined
- Nov 12, 2018
- Messages
- 6
- Reaction score
- 1
- First Language
- English
- Primarily Uses
- RMMV
TLDR: I think NWJS's working directory isn't being set properly... maybe.
I'm working on something that reads and writes files and ran into some odd behaviour. For example:
Which is a simple plugin which gives commands to either writes a file to a fixed name on a fixed path (WriteTest), or with no path (WriteTestNP).
With no path it writes to the project folder as you would expect. But with a path it tries to write to "c:\testpath\testfile.txt".
Seemed easy enough to fix. Just change "let path = "/" + unformattedPath + "/";" to remove the first forward slash.
But the thing is I found this example and it had the same problem when I ran it:
https://forums.rpgmakerweb.com/index.php?threads/node-js-making-directories.80143/
Which makes me think the cause of the odd behaviour is probably on my end and my "fix" is going to cause problems down the line. The obvious answer is that the NWJS working directory is for some reason is not set correctly to the project folder. But then removing the forward slash shouldn't help.
I feel like I'm running in circles on this. Anyone have any idea what's going on?
I'm working on something that reads and writes files and ran into some odd behaviour. For example:
Code:
//=============================================================================
// filePath.js
//=============================================================================
/*:
* @plugindesc tests behaviour when writing a file
* @author RSJG
*
* @help Yes please.
*/
{
fs = require("fs");
function getPath(unformattedPath) {
let path = "/" + unformattedPath + "/";
//reg-ex magic here
console.log("file path is: " + path); //"file path is: /testpath/""
return path;
}
function writeFile(path, name, data){
let wPath = (path === "") ? "" : getPath(path);
fs.writeFileSync(wPath + name, data);
}
const Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function (command, args) {
Game_Interpreter_pluginCommand.call(this, command, args);
if (command.toLowerCase() === "writetest") {
writeFile("testpath","testfile2.txt","Hello Path + File!");
}
if (command.toLowerCase() === "writetestnp") {
writeFile("","testfile1.txt","Hello File!");
}
}
};
With no path it writes to the project folder as you would expect. But with a path it tries to write to "c:\testpath\testfile.txt".
Seemed easy enough to fix. Just change "let path = "/" + unformattedPath + "/";" to remove the first forward slash.
But the thing is I found this example and it had the same problem when I ran it:
https://forums.rpgmakerweb.com/index.php?threads/node-js-making-directories.80143/
Which makes me think the cause of the odd behaviour is probably on my end and my "fix" is going to cause problems down the line. The obvious answer is that the NWJS working directory is for some reason is not set correctly to the project folder. But then removing the forward slash shouldn't help.
I feel like I'm running in circles on this. Anyone have any idea what's going on?

