Add function when loading

I'm working with an evented titlescreen. The only problem i have so far is that when a player loads a file, the pictures of the evented titlescreen are still shown. I'm not gonna put an event on every map to get the pictures away, so i search and found the javascript call:

$gameScreen.clearPictures();

Now I have to know how to execute this when a gamefile is loaded. I know some javascript, but i'm not familiar the engine yet. Can someone put me in the right direction as to where/how i add this function when a gamefile is loaded? Thanks!
You could do one of two things. You can make a plugin to alias and add the code to clear pictures to the loadGameWithoutRescue method, or you could do all that with a script command. I don't recommend the second option, as it will make debugging a bit harder to pinpoint if this ends up causing any issues in the future. So, my recommendation is this:

/*: * @plugindesc Clears game pictures on game load * @author Zalerinian */(function($) { var DM_lgwr_OiNirionsoie = $.loadGameWithoutRescue $.saveGameWithoutRescue = function(id) { $gameScreen.clearPictures(); var ret = DM_lgwr_OiNirionsoie.call(this, id) return ret && true; }})(DataManager);Now, I didn't test this, so I'm not 100% sure it'll work fine, but I think it should. Since you're using an evented menu, I put the call to clear the screen BEFORE the save file is loaded, as the save file would change what $gameScreen refers to, and those images would probably be stuck in limbo. So give it a try and let me know how it goes.
Thanks!

So rather than editing the existing files like in previous versions we alias new functions through seperate plugins? I'm happy I finally understand this code, which was never really the case in ruby.
Really you never should have edited the default files. We aliased things in ruby too, but with MV people aren't as likely to change the default files because 1. there's no built in script editor, and 2. The default scripts are not giant files, and it scares people 😛

I take it by your reply that the code worked fine?
I tried it now but it didn't work, i'm trying to find out why, but could use some help i'm afraid. The pictures are still showing like before.
I tried it now but it didn't work, i'm trying to find out why, but could use some help i'm afraid. The pictures are still showing like before.
The answer to your question is because I'm a complete idiot. I accidentally rewrote saveGameWithoutRescue, so saving would now try to load the game! Whoops! But at least it's an easy fix:

Code:
/*: * @plugindesc Clears game pictures on game load * @author Zalerinian */ (function($) {  var DM_lgwr_OiNirionsoie = $.loadGameWithoutRescue  $.loadGameWithoutRescue = function(id) {    $gameScreen.clearPictures();    var ret = DM_lgwr_OiNirionsoie.call(this, id)    return ret && true;  }})(DataManager);
Well, let's feel bad together, because i should have seen that too. Thank you for all your help to me and the community Zalerinian.

General question, is there a particular reason why this var is called var DM_lgwr_OiNirionsoie. If so, what does it refer to?
That is the alias. Typically, in my plugin I have an object, Zale, that I use to store settings for each plugin in a global scope, and I'd so something like Zale.PluginName.Alias = the function I'm aliasing. However, in this case I didn't go through the process of creating the Zale object, like this:

var Zale = Zale || {};Zale.PluginName = {};The || {} part makes sure we don't overwrite the object if it already exists because another of my plugins defined it.

Since I didn't have any of that fancy stuff, and the functionality itself is stored in an anonymous function, variables created there don't get released to the global scope. With that in mind, I created the alias right there. The format of it is just my naming scheme for aliases, AbbrievatedClass_AbbreviatedFunctionName_ABunchOfSpam. The bunch of spam at the end is just to further guarantee I'm not aliasing a method twice with the same name, because that causes issues with the function calling itself.

If it bothers you, you can safely change the alias to something simple, like "alias", or "oldLoadGameWithoutRescue". Just make sure you change it in both places, and you should be fine!

Original thread: https://forums.rpgmakerweb.com/threads/add-function-when-loading.47318/