password TXT file

Hello everyone, I would like to know how to make sure that within a TXT file there is the exact word.
This command should be used as a password.

I add an example
.
Please don't double post (posting underneath yourself), keep everything contained in a single message, until someone else responds.

This would probably need a plugin though, so I'm moving this to plugin requests.
Please don't double post (posting underneath yourself), keep everything contained in a single message, until someone else responds.

This would probably need a plugin though, so I'm moving this to plugin requests.
thanks!
If you want to have this game only for windows, linux or mac, you can use this script as the event's script command:
Code:
var fs = require ("fs");
$gameVariables.setValue (1, fs.readFileSync ("./file.txt", {encoding: "utf-8"}));
and then use a conditional branch - variable 1 is equal to script: "password"

For browser games the situation is a bit more complicated.
Code:
var xhr = new XMLHttpRequest();
xhr.open ("GET", "text.txt");
xhr.send ();
xhr.onload = function () {$gameVariables.setValue (1, xhr.response)};
and after that you need to have a loop that checks whether variable 1 is 0. If not, break out of the loop and check for the value similarly to the windows/linux/mac version.
When I saw this I already found several ways to "hack" your idea... Hahaha
Seriously now... if you really need to do in this way, then you should think on some encryption...
IMHO better way would be storing password in variable X and compare it with variable Y. But if you insist on txt file method then @Poryg gave you right answer.
If you want to have this game only for windows, linux or mac, you can use this script as the event's script command:
Code:
var fs = require ("fs");
$gameVariables.setValue (1, fs.readFileSync ("./file.txt", {encoding: "utf-8"}));
and then use a conditional branch - variable 1 is equal to script: "password"

For browser games the situation is a bit more complicated.
Code:
var xhr = new XMLHttpRequest();
xhr.open ("GET", "text.txt");
xhr.send ();
xhr.onload = function () {$gameVariables.setValue (1, xhr.response)};
and after that you need to have a loop that checks whether variable 1 is 0. If not, break out of the loop and check for the value similarly to the windows/linux/mac version.
Thank you very much
When I saw this I already found several ways to "hack" your idea... Hahaha
Seriously now... if you really need to do in this way, then you should think on some encryption...
IMHO better way would be storing password in variable X and compare it with variable Y. But if you insist on txt file method then @Poryg gave you right answer.
Poryg's is fine, thank you very much anyway.
If you want to have this game only for windows, linux or mac, you can use this script as the event's script command:
Code:
var fs = require ("fs");
$gameVariables.setValue (1, fs.readFileSync ("./file.txt", {encoding: "utf-8"}));
and then use a conditional branch - variable 1 is equal to script: "password"

For browser games the situation is a bit more complicated.
Code:
var xhr = new XMLHttpRequest();
xhr.open ("GET", "text.txt");
xhr.send ();
xhr.onload = function () {$gameVariables.setValue (1, xhr.response)};
and after that you need to have a loop that checks whether variable 1 is 0. If not, break out of the loop and check for the value similarly to the windows/linux/mac version.

Nothing happens...
Do I have to put you in a conditional branch by any chance?
So you kinda were alerted to avoid double post and you did a triple post...

But by the way, check if the .txt file has the same name as in the code given and is in the same folder as the game.exe
No, you don't need to. You should keep the "password" surrounded by the " " though.
I used the above mentioned script to make my own function:

function CensorshipCheck() {
var fs = require ("fs");
$gameVariables.setValue (267, fs.readFileSync ("./Censorship.txt", {encoding: "utf-8"}));

}
CensorshipCheck();

This works well, apart from it producing a "missing file" error if the Censorship.txt file isn't present. How can I avoid this error message? In other words; how do I make the function do nothing if the Censorship.txt file is missing?
try {
var x = fs.readFileSync (your things);
$gameVariables.setValue (267, x);
}catch (e) {};
Not sure if try catch catches the error, but hopefully it does. Otherwise you'd have to use fs.readdir to find whether the returned array contains the filename.
@Poryg reminds me of this 🙂

Another option (that I typically use) is the fs.existssync function.

Original thread: https://forums.rpgmakerweb.com/threads/password-txt-file.103380/