Creating auto-updating message window. (SOLVED)

Well, what do you know, adding messaging windows to the mix ended up being complicated after all.

I'm trying to do something relatively straightforward: create a small pop-up window that appears in the upper-right corner when called, cycles through a set of messages automatically, then closes itself once there are no more messages.

Spoiler: Code Block
Code:
 var alertWindow = null;
 //Constructs message window for new/updated items.
 function showIntelMessage(intelMsg) {
     if (alertWindow) {
         alertWindow.addContents(intelMsg);
     } else {
         alertWindow = new Window_IntelAlert(intelMsg);
     }
 };

function Window_IntelAlert() {this.initialize.apply(this, arguments);}
Window_IntelAlert.prototype = Object.create(Window_Message.prototype);
Window_IntelAlert.prototype.constructor = Window_IntelAlert;

Window_IntelAlert.prototype.initialize = function(str) {
    Window_Message.prototype.initialize.call(this, Graphics.boxWidth - this.windowWidth(), 0, this.windowWidth(), this.windowHeight());
        this.clockTime = Number(intelParameters["AlertsDelay"]);
    if (isNaN(this.clockTime)) {
        this.clockTime = 2500;
    } else {
        this.clockTime *= 1000;
    }
    this.msgWidth =  this.contents.measureTextWidth(str);
    this.openness = 0;
    this.pendingContents = [];
    this.initMembers();
    this.createSubWindows();
    this.updatePlacement();
    this.contents.drawText(str);
    this.open();
    setTimeout(this.checkForMoreContents(), this.clockTime);
};

Window_IntelAlert.prototype.maxRows = function() {return 1;};
Window_IntelAlert.prototype.getWidth = function() {return this.msgWidth + this.padding();};

Window_IntelAlert.prototype.addMessage = function(str) {
    this.pendingContents.push(str);
};

Window_IntelAlert.prototype.updateContents = function() {
    var newContents = this.pendingContents.unshift();
    var newWidth = this.contents.measureTextWidth(newContents);
    if (this.msgWidth < newWidth) {
        this.msgWidth = newWidth;
    }
    this.contents.drawText(newContents, 0, 0, this.contentsWidth(), this.lineHeight());
    this.refresh();
};

Window_IntelAlert.prototype.checkForMoreContents = function(){
    if (this.pendingContents.length > 0) {
        this.updateContents();
        setTimeout(this.checkForMoreContents(), this.clockTime);
    } else {
        this.close();
    }
};

Window_IntelAlert.prototype.refresh = function() {
    this.contents.clear();
};
As written, the code runs even if multiple messages are sent to it, but the window never appears.

I had originally written the window as being dependent upon a continuous scene; THIS causes a crash with 'Cannot read property 'addChild' of undefined.'
This is most likely happening during the Scene_Base initialization, on account of the fact that I'm trying to instantiate it as a variable instead of via a handler.
Spoiler: Code Block (Window w/scene)
Code:
 //Comes into play if multiple items are added.
 var alertWindowScene = null;
 //Constructs message window for new/updated items.
 function showIntelMessage(intelMsg) {
    if (alertWindowScene) {
        alertWindowScene.addMessage(intelMsg);
    } else {
        alertWindowScene = new Scene_IntelAlerts(intelMsg);
    }
 }

function Scene_IntelAlerts() {this.initialize.apply(this, arguments);}
Scene_IntelAlerts.prototype = Object.create(Scene_Base.prototype);
Scene_IntelAlerts.prototype.constructor = Scene_IntelAlerts;
Scene_IntelAlerts.prototype.initialize = function(str) {
    Scene_Base.prototype.initialize.call(this);
    this.clockTime = Number(intelParameters["AlertsDelay"]);
    if (isNaN(this.clockTime)) {
        this.clockTime = 2500;
    } else {
        this.clockTime *= 1000;
    }
 
    this._alertWindow = new Window_IntelAlert(str);
    this.addWindow(this._alertWindow);
    this.timeOut(this.checkForMoreContents(), this.clockTime);
 
};

//Recursive function to cycle through pending contents.
Scene_IntelAlerts.prototype.checkForMoreContents = function(){
    if (this._alertWindow.pendingContents.length > 0) {
        this._alertWindow.updateContents();
        this.timeOut(this.checkForMoreContents(), this.clockTime);
    } else {
        this._alertWindow.close();    
    }
};

Scene_IntelAlerts.prototype.addMessage = function(str) {
    if (this._alertWindow) {
        this._alertWindow.pendingContents.push(str);
    } else {
        this._alertWindow = new Window_IntelAlert(str);
        this.addWindow(this._alertWindow);
        this.timeOut(this.checkForMoreContents(), this.clockTime);
    }
};

function Window_IntelAlert() {this.initialize.apply(this, arguments);}
Window_IntelAlert.prototype = Object.create(Window_Message.prototype);
Window_IntelAlert.prototype.constructor = Window_IntelAlert;

Window_IntelAlert.prototype.initialize = function(str) {
    Window_Message.prototype.initialize.call(this, Graphics.boxWidth - this.windowWidth(), 0, this.windowWidth(), this.windowHeight());
    this.msgWidth =  this.contents.measureTextWidth(str);
    this.openness = 0;
    this.pendingContents = [];
    this.initMembers();
    this.createSubWindows();
    this.updatePlacement();
};

Window_IntelAlert.prototype.maxRows = function() {return 1;};
Window_IntelAlert.prototype.getWidth = function() {return this.msgWidth + this.padding();};

Window_IntelAlert.prototype.updateContents = function() {
    var newContents = this.pendingContents.unshift();
    var newWidth = this.contents.measureTextWidth(newContents);
    if (this.msgWidth < newWidth) {
        this.msgWidth = newWidth;
    }
    this.refresh();
    this.contents.drawText(newContents, 0, 0, this.contentsWidth(), this.lineHeight());
};

Window_IntelAlert.prototype.refresh = function() {
    this.contents.clear();
    this.width = this.getWidth();
};
Which way is closer to working, and what do I need to do to get it there?


EDIT:
After consulting with the RMMV Script Calls Excel sheet, I found a means of making the message display without needing to muck about with another Scene_ extension:
Spoiler: New Code
Code:
 //Constructs message window for new/updated items.
function AlertHandler() {
    this.alertQueue = [];
    this.isActive = false;
    if (intelParameters.AlertDelay) {
        this.clock = intelParameters.AlertDelay * 1000;
    } else {
        this.clock = 3000;
    }
};

//Used to determine whether an alert gets shown immediately.
AlertHandler.prototype.processAlert = function(str) {
    if (this.isActive){
        this.alertQueue.push(str);
    } else {
        this.isActive = true;
        this.intelMessage(str);
        //Checks for another message in the queue after the initial call based on the relevant perameter.
        setTimeout(this.processQueue(), this.clock);
    }
};

AlertHandler.prototype.processQueue = function() {
    this.isActive = (this.alertQueue.length > 0);
    if (this.isActive) {
        this.intelMessage(this.alertQueue.unshift());
        setTimeout(this.processQueue(), this.clock);
    }
};

//Handles the creation of the messages.
AlertHandler.prototype.intelMessage = function(str) {
        //$gameMessage.setFaceImage('Actor1',0);
        $gameMessage.setBackground(1);
        $gameMessage.setPositionType(1);
        $gameMessage.add(str);
};
The issues now are that setTimeout doesn't work like it's supposed to:
1) Instead of waiting it simply performs the operation immediately,
2) Instead of appearing simultaneously with the NPC's text box, it only appears before or after the message.
3) Instead of removing itself automatically, it requires additional input from the player.

I'm going to continue looking into a way to make the text appear independently of the window; is there a function that works similarly to setTimeout in the context of RPG Maker MV?


EDIT 2:
I've opted to add the functionality using Yanfly's Gab Message plugin, since what I want is essentially an application of those windows.
I'll eventually try to splice in the relevant code to remove any compatibility issues, but this should service perfectly for the moment.

Original thread: https://forums.rpgmakerweb.com/threads/creating-auto-updating-message-window-solved.82679/