Insertion of plugin command in a script

● ARCHIVED · READ-ONLY
Started by JesusGames 9 posts View original ↗
  1. I have a problem, do I have to insert a plugin command in a conditional branch like I do? I thought about inserting it through a script in the script section.

    This is the code inserted in the plugin:

    Code:
    const fs = require ('fs')
    
    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
    };


    Thanks!
  2. you can't insert a plugin command by script code. Plugin commands can only be used by the event command for them.

    if you want to call another plugin from a plugin you're writing, then what you need to do is to analyse the plugin you want to command and see which functions inside the plugin are triggered and called by the plugin command, and then call those functions directly in your plugin or script.
  3. [QUOTE = "Andar, post: 898171, member: 11882"]
    So I can't put a plugin command in a conditional branch?
  4. Andar said:
    you can't insert a plugin command by script code. Plugin commands can only be used by the event command for them.

    if you want to call another plugin from a plugin you're writing, then what you need to do is to analyse the plugin you want to command and see which functions inside the plugin are triggered and called by the plugin command, and then call those functions directly in your plugin or script.
    So I can't put a plugin command in a conditional branch?
  5. where are you asking?
    there is no problem to put a plugin command into the branches of an event command "conditional branch", because that is inside an event.
    however it is not a good idea to place a plugin command inside a script - and there it doesn't matter if the script has a conditional branch or not.

    your question makes no sense, because a conditional branch doesn't matter for plugin commands - what matters for a plugin command is if it is used in an event or in a script/plugin. Because a plugin command is an event command and should not be used outside of events.
  6. Andar said:
    where are you asking?
    there is no problem to put a plugin command into the branches of an event command "conditional branch", because that is inside an event.
    however it is not a good idea to place a plugin command inside a script - and there it doesn't matter if the script has a conditional branch or not.

    your question makes no sense, because a conditional branch doesn't matter for plugin commands - what matters for a plugin command is if it is used in an event or in a script/plugin. Because a plugin command is an event command and should not be used outside of events.
    the code written in the first post is used to read what is written inside a TXT file and if the file contains the phrase/word written inside the command.
    I want to do this.
  7. No, you cannot put a plugin command as the Script part of a conditional branch. Plugin commands generally don't return a true/false value (or any value) anyway, so it would not make sense to put one there.

    What is in the plugin description & parameters? I'm guessing that it will turn on a switch if the file contains the required text, or turn it off if it doesn't.

    Actually, looking at the image in your last post, and your first post again, that is not a plugin command. It is just a function. And in that case, yes, you should be able to put it as the script portion of a conditional branch. But it depends on how the function is defined - what its context is.

    Have you tried doing it the way you initially thought? What happens when you do? If you get an error, open up the dev tools (F8) and go to the Console, and show us a screenshot of what it says.
  8. Shaz said:
    No, you cannot put a plugin command as the Script part of a conditional branch. Plugin commands generally don't return a true/false value (or any value) anyway, so it would not make sense to put one there.

    What is in the plugin description & parameters? I'm guessing that it will turn on a switch if the file contains the required text, or turn it off if it doesn't.

    Actually, looking at the image in your last post, and your first post again, that is not a plugin command. It is just a function. And in that case, yes, you should be able to put it as the script portion of a conditional branch. But it depends on how the function is defined - what its context is.

    Have you tried doing it the way you initially thought? What happens when you do? If you get an error, open up the dev tools (F8) and go to the Console, and show us a screenshot of what it says.
    Does not give mistakes tells me directly false.
    The purpose of the command would be to read the "Password" inside the file.
  9. The correct filepath is not "/GameFolder/passPC.txt", but "./GameFolder/passPC.txt". You need the dot in front to specify that the filepath is going from the home directory of the game. Also, since the readFile is async, it might not have enough time to influence the result variable before it gets returned as false. I suggest substituting readFile in your function for readFileSync.
    Also, I think try and catch is pointless here. You're never going to get a file not found error, since it's handled by C++ and mot by javascript.