External password in a TXT file

Hi everyone I have a problem I just started using rpg maker mv and I'm trying to be able to use a TXT file creation system. Thanks to Aloe Guvner who passed me a code for creating TXT files but now I would like an event to be able to create a conditional branch so that if the TXT file says "pass" then it can proceed if there is not written "pass" the undo event.

Thanks


the create file TXT code is:
Code:
const path = require ('path');
const base = path.dirname (process.mainModule.filename);
const fs = require ('fs');
const fileText = "Prima riga \ nLa seconda riga";
fs.writeFileSync (base + '/test.txt', fileText);
Just read the file contents and check if the string returned contains the password you want.

I'm assuming your placing the code in a plugin of your own. If not then you will have to edit the code a little bit, or place it at the top of rpg_core.js with a unique function name like $containsPassword

PHP:
function containsPassword (path, password) {
  let result = false
  try {
    fs.readFile(path, 'utf8', (data) => {
      result = data.includes(password)
    })
  } catch (error) {
    throw new Error(error)
  }
  return result
}

Then in an event you can use in a conditional containsPassword('path/to/text.txt', 'password') this will return true or false depending if the password is a match or not.
Just read the file contents and check if the string returned contains the password you want.

I'm assuming your placing the code in a plugin of your own. If not then you will have to edit the code a little bit, or place it at the top of rpg_core.js with a unique function name like $containsPassword

PHP:
function containsPassword (path, password) {
  let result = false
  try {
    fs.readFile(path, 'utf8', (data) => {
      result = data.includes(password)
    })
  } catch (error) {
    throw new Error(error)
  }
  return result
}

Then in an event you can use in a conditional containsPassword('path/to/text.txt', 'password') this will return true or false depending if the password is a match or not.

Thanks you
Just read the file contents and check if the string returned contains the password you want.

I'm assuming your placing the code in a plugin of your own. If not then you will have to edit the code a little bit, or place it at the top of rpg_core.js with a unique function name like $containsPassword

PHP:
function containsPassword (path, password) {
  let result = false
  try {
    fs.readFile(path, 'utf8', (data) => {
      result = data.includes(password)
    })
  } catch (error) {
    throw new Error(error)
  }
  return result
}

Then in an event you can use in a conditional containsPassword('path/to/text.txt', 'password') this will return true or false depending if the password is a match or not.
I inserted your code into a plugin.
Then I activated the plugin and inserted the command in a conditional branch
but he gives me the following mistake:

ReferenceError: fs is not defined.

How can I fix it?
@JesusGames You need to declare the fs module.

At the start of the plugin file where you have inserted the method provided by LTN Games, insert a line like this

Code:
const fs = require('fs')

The error should disappear 😤
cessario dichiarare il modulo
@JesusGames You need to declare the fs module.

At the start of the plugin file where you have inserted the method provided by LTN Games, insert a line like this

Code:
const fs = require('fs')

The error should disappear 😤
I inserted the line of code that you recommended and now "works" but now follows this problem:
This is one of 5 threads you have opened with this query. The one at https://forums.rpgmakerweb.com/inde...plugin-command-in-a-script.99902/#post-898195 appears to be the active one.

Moderator note: Closing, as this is a duplicate thread.

Original thread: https://forums.rpgmakerweb.com/threads/external-password-in-a-txt-file.99757/