MV Custom error message

I plan to soon release a demo of my game, however it may have bugs

my goal is to make a custom error message display

for example, instead of "Couldn't find img/actors/actor1.png" and the button "Retry" it would display "If you are reading this, I messed up somehow" and a "Exit" button (which would close the game obviously)

is that possible by modyfing the core or something?
Ok I think I figured it out, in the core file, line 1993 there is a string(?) probably reffering to what message will be displayed I also found a button text string(?) which displays the text on the button two lines later, on line 2000 2001, there is probably the script that will execute after pressing the button, going to test it out
It's possible, but sounds very unusual. Do you not want to get useful error reports? 😅
Spoiler: Relevant excerpts (rpg_core.js) - comments mine
JavaScript:
// All errors
Graphics._makeErrorHtml = function(name, message) {
    return ('<font color="yellow"><b>' + name + '</b></font><br>' +
            '<font color="white">' + message + '</font><br>');
};

// Loading errors
Graphics.printLoadingError = function(url) {
    if (this._errorPrinter && !this._errorShowed) {
        this._errorPrinter.innerHTML = this._makeErrorHtml('Loading Error', 'Failed to load: ' + url);
        var button = document.createElement('button');
        button.innerHTML = 'Retry';
        button.style.fontSize = '24px';
        button.style.color = '#ffffff';
        button.style.backgroundColor = '#000000';
        button.onmousedown = button.ontouchstart = function(event) {
            ResourceHandler.retry();
            event.stopPropagation();
        };
        this._errorPrinter.appendChild(button);
        this._loadingCount = -Infinity;
    }
};
I strongly recommend you do not alter rpg_core.js directly. Copy one or both of these methods into a separate .js file, make what edits you like, then import your new .js file as a plugin. This will leave you with a custom plugin that overrides the game's default error display.

For the effect you're requesting, you could try this:
Spoiler: Suggested plugin code
JavaScript:
Graphics.printLoadingError = function(url) {
  if (this._errorPrinter && !this._errorShowed) {
    this._errorPrinter.innerHTML = this._makeErrorHtml("Error", "I messed up");
    var button = document.createElement('button');
    button.innerHTML = 'Exit';
    button.style.fontSize = '24px';
    button.style.color = '#ffffff';
    button.style.backgroundColor = '#000000';
    button.onmousedown = button.ontouchstart = function(event) {
      SceneManager.resume();   // exit will not take effect while manager is stopped
      SceneManager.exit();
      event.stopPropagation();
    };
    this._errorPrinter.appendChild(button);
  }
};
[Edit: added SceneManager.resume() to my suggested override.]
It's possible, but sounds very unusual. Do you not want to get useful error reports? 😅
Spoiler: Relevant excerpts (rpg_core.js) - comments mine
JavaScript:
// All errors[/INDENT]
[INDENT]Graphics._makeErrorHtml = function(name, message) {[/INDENT]
[INDENT]    return ('<font color="yellow"><b>' + name + '</b></font><br>' +[/INDENT]
[INDENT]            '<font color="white">' + message + '</font><br>');[/INDENT]
[INDENT]};[/INDENT]
[INDENT][/INDENT]
[INDENT]// Loading errors[/INDENT]
[INDENT]Graphics.printLoadingError = function(url) {[/INDENT]
[INDENT]    if (this._errorPrinter && !this._errorShowed) {[/INDENT]
[INDENT]        this._errorPrinter.innerHTML = this._makeErrorHtml('Loading Error', 'Failed to load: ' + url);[/INDENT]
[INDENT]        var button = document.createElement('button');[/INDENT]
[INDENT]        button.innerHTML = 'Retry';[/INDENT]
[INDENT]        button.style.fontSize = '24px';[/INDENT]
[INDENT]        button.style.color = '#ffffff';[/INDENT]
[INDENT]        button.style.backgroundColor = '#000000';[/INDENT]
[INDENT]        button.onmousedown = button.ontouchstart = function(event) {[/INDENT]
[INDENT]            ResourceHandler.retry();[/INDENT]
[INDENT]            event.stopPropagation();[/INDENT]
[INDENT]        };[/INDENT]
[INDENT]        this._errorPrinter.appendChild(button);[/INDENT]
[INDENT]        this._loadingCount = -Infinity;[/INDENT]
[INDENT]    }[/INDENT]
[INDENT]};
I strongly recommend you do not alter rpg_core.js directly. Copy one or both of these methods into a separate .js file, make what edits you like, then import your new .js file as a plugin. This will leave you with a custom plugin that overrides the game's default error display.

For the effect you're requesting, you could try this:
Spoiler: untested
JavaScript:
Graphics.printLoadingError = function(url) {[/INDENT]
[INDENT]  if (this._errorPrinter && !this._errorShowed) {[/INDENT]
[INDENT]    this._errorPrinter.innerHTML = this._makeErrorHtml("Error", "I messed up");[/INDENT]
[INDENT]    var button = document.createElement('button');[/INDENT]
[INDENT]    button.innerHTML = 'Exit';[/INDENT]
[INDENT]    button.style.fontSize = '24px';[/INDENT]
[INDENT]    button.style.color = '#ffffff';[/INDENT]
[INDENT]    button.style.backgroundColor = '#000000';[/INDENT]
[INDENT]    button.onmousedown = button.ontouchstart = function(event) {[/INDENT]
[INDENT]      SceneManager.exit();[/INDENT]
[INDENT]      event.stopPropagation();[/INDENT]
[INDENT]    };[/INDENT]
[INDENT]    this._errorPrinter.appendChild(button);[/INDENT]
[INDENT]  }[/INDENT]
[INDENT]};
Welp, I can make something like "If you are reading this, I somehow messed up, use this as a reference, Unable to load "<FileName>"" 😀

Yea I'll make a copy of the original core 😛
So the custom error works, the button however doesn't do anything, any idea how to fix this?
EDIT: Found out how, at line 2000, replace "SceneManager.exit();" (which would be a exit command for VXAce) with "$scene = window.close();" where $scene is like VXAce' SceneManager and window.close would be exit 😀
Moderator note: JS/Plugin Support

Double-post notice: VyZi
Good you found a solution (and that you recognise the importance of helpful error messages!). 😂

Some closing remarks:
  1. SceneManager.exit() certainly is the default RPG Maker MV way to end the game. However, I overlooked the fact that it won't have any effect while the SceneManager is stopped, e.g. after an error has occurred. A solution is to add a SceneManager.resume(); line just before the exit one. I'll edit the fix into my previous post~ 🙏

  2. window.close() is a method from NW.js, and is what's closing the window for you. I feel like it's better practice to interface with the game's SceneManager directly, but ultimately that passes through the same call via the manager's terminate method.

  3. $scene does not exist in the core scripts. With this statement you are either:

    • Interfacing with some other custom code (likely irrelevant since you tell the window to close in the same line), or

    • Trying to implicitly define a new global variable (again, probably irrelevant at this point and would throw an error in strict mode).

    So I suggest removing the $scene = part~ 😮‍💨

Original thread: https://forums.rpgmakerweb.com/threads/custom-error-message.131527/