External password in a TXT file

● ARCHIVED · READ-ONLY
Started by JesusGames 7 posts View original ↗
  1. 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);
  2. 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.
  3. LTN Games said:
    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
  4. LTN Games said:
    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?
  5. @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 :kaopride:
  6. Gamefall Team said:
    cessario dichiarare il modulo
    Gamefall Team said:
    @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 :kaopride:
    I inserted the line of code that you recommended and now "works" but now follows this problem: