Referencing another function and weird booleans in javascript for rpgmaker MZ

I’m learning Javascript by using it in the context I want it for, rpg maker MZ, to slightly override it’s error handling. It would essentially tell the engine to more or less skip playing the missing audio file, and to display a custom error message.

I’m having two issues.

  • I think I’m potentially referencing the original function incorrectly because it doesn’t appear to be functioning entirely. It’s functioning enough to know that the file is missing, but it no longer seems to be recognizing the file is there even when it’s put back into place.

  • I’m having an issue with a boolean returning true, when I want it returning false be default.

I’ve managed to get pretty far with it using google, documentation, and combing through other plugins to see how they work, but on this I’m stuck. I’m not exactly sure what it is I’m missing.

Here is what I have for the plugin so far.

/*:
@target MZ
@plugindesc V1 MissingFileSkipper
@author Quizicalgin
@url 
@help 

@param Missing Error Message
@type string
@default "%s could not be found. Please contact the dev at (your url here)."
@desc Error message if a file is missing.

@param Show in Console?
@type boolean
@default false
@desc Error message is shown in the console instead
*/

// variable set up to prevent conflicts
var ftp = ftp ||{}

// Makes sure that the parameters set from the editable options will be used.
var parameters = PluginManager.parameters("FTP_MissingFileSkipper");

// Connects the parameters to the code that handles the errors and if it's going to use the console or not
var MissingError = parameters["Missing Error Message"];
var ConsoleMsg = parameters["Show in Console?"] === "false";

    
ftp.MissingFileSkipper = function () {
    
    // references the original audio functions so they can still be called
    AudioManager._OGPlaySe = AudioManager.playSe;   
    
    AudioManager.playSe = function (se) {
        if (this._isError = true) {
            showMissingError(se.name);          
        } 
        else {
            this._OGPlaySe(se.name);
        }
    };
        
    // Determines whether ther error shows up in console, or as a msgbox.
    showMissingError = function (filename) {
        const message = MissingError.replace("%s", filename);
        if (ConsoleMsg) {
            console.warn(message);
        }
        else {
            alert(message);
        }
    };  
    
};
// Calls the now defined function so that it's used in game.
ftp.MissingFileSkipper ();

-Trying to reference problem-
AudioManager._OGPlaySe = AudioManager.playSe; is supposed to reference the pre-existing function so that I can override, but still use the original function to play sound, in this case a sound effect.

The only other way I’ve tried to write it is const AudioManager._OGPlaySe = AudioManager.playSe; which resulted in a “Missing initializer in const declaration” error that I wasn’t able to figure a way around either, since it looks initialized to me, or at least that it should?

-Flipflopped boolean-
For the ConsoleMsg variable I have tried:

  • == “false”
  • === “false
  • == ‘false’
  • === ‘false’

and in the if arg for showMissingError I have tried:

  • ConsoleMsg == true
  • ConsoleMsg === true
  • ConsoleMsg == ‘true’
  • ConsoleMsg === ‘true’
  • ConsoleMsg == “true”
  • ConsoleMsg === “true”

It all still results in it being the inverse of what I would like it to be, which is false making it so it prints to an alert box, where true would make it use the console instead.

Extra details:

I was initially trying to run the error handing as try/catch, but it continued to default to the engine’s error message and opted to scrap the approach with my current limited knowledge set.

I had also tried to override the error handling functions for audio in the engine, but when looking at it in the console it kept showing that it was trying to play the file despite it not being there, and was counting up the attempts. Had to scrap that idea since I suspected it could result in some laggy gameplay if allowed to go on.