RPG Maker Forums

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:

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!");
        }
    }

};
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?

Latest Threads

Latest Posts

Latest Profile Posts

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.

Forum statistics

Threads
106,035
Messages
1,018,455
Members
137,821
Latest member
Capterson
Top