File creation from game?

I'm fairly new to RPG Maker MV, but I've used RPG Maker VX Ace in the past.

I want to know if it's possible for the game to create a text file (.txt) and save it to the game's file.

What I'm trying to do is make a randomly generated, 5-digit numerical password that must be input before the game can be played. I've tried looking it up, but the results were just for websites. I just wanted to know if it was even possible.
You can indeed do this, sort of (I don't think it works for web deployments)! Consider the following example:

Code:
var data = "Hello world!";
var fs = require('fs');
var filePath = "c:\\users\\your.name\\documents\\games\\your.game.title\\helloworld.txt";
fs.writeFileSync(filePath, data);
Will the game support mobile or web, or is it just desktop? What about Mac or Linux systems?
Will the game support mobile or web, or is it just desktop? What about Mac or Linux systems?
Desktop! I think it'll just be for PC users
You can indeed do this, sort of (I don't think it works for web deployments)! Consider the following example:

Code:
var data = "Hello world!";
var fs = require('fs');
var filePath = "c:\\users\\your.name\\documents\\games\\your.game.title\\helloworld.txt";
fs.writeFileSync(filePath, data);
I'll give it a try! What if the file directory is different? Like, if I let another person download it, it wouldn't be the same path as my file, right?
Just for the record, if you did want to support mobile or web deployments, I think you could store the password in ConfigManager instead of writing it to a file. Anything in ConfigManager is automatically saved to the game's options file.

I'll give it a try! What if the file directory is different? Like, if I let another person download it, it wouldn't be the same path as my file, right?
Just write the path relative to your project directory, no need for a full path from the root of C:. Also, I'd suggest using / instead of \\ for the directory separator if you think there's any chance you might want to make a Mac version. I'm not certain if \\ would be an issue on a Mac, but I know / works on both, so...
Just for the record, if you did want to support mobile or web deployments, I think you could store the password in ConfigManager instead of writing it to a file. Anything in ConfigManager is automatically saved to the game's options file.

Just write the path relative to your project directory, no need for a full path from the root of C:. Also, I'd suggest using / instead of \\ for the directory separator if you think there's any chance you might want to make a Mac version. I'm not certain if \\ would be an issue on a Mac, but I know / works on both, so...
Thank you so much! I might make a Mac Version after I perfect the PC version, so this really helps a lot!!! 😀

Original thread: https://forums.rpgmakerweb.com/threads/file-creation-from-game.124493/