MZ About Scenes and Windows update function...

I made a Window for a Scene I created, with an update function like this:
JavaScript:
QuestDetailWindow.prototype.update = function () {
    Window_Base.prototype.update.call(this);
    this.drawAllItems();
}

QuestDetailWindow.prototype.drawAllItems = function () {
    this.drawText('Hello world', 0, 0);
}

Everything works just fine, Hello World displays at the top of my window. Now I've put another update function, but for my Scene:
JavaScript:
QuestScene.prototype.update = function () {
    if (Input.isTriggered('cancel')) {
        SceneManager.pop();
    }
}

The problem is that the update function from the QuestDetailWindow is not being called anymore, so the message Hello World is not being displayed. Is this a common behavior? Can't I have a Scene AND it's Windows updating at the same time?

My workaround for this: calling the update function for the Window inside the Scene update function.
Hi!
I think it should work., I mean, with the code you have shown.
JavaScript:
QuestScene.prototype.update = function () {
    // Maybe this had to have a Scene_something.prototype.update()
    if (Input.isTriggered('cancel')) {
        SceneManager.pop();
    }
}
If your scene is inherited from somewhere, I think that is what is being missed.


Can't I have a Scene AND it's Windows updates at the same time?
Yes, you can.

Where you are adding your window? To the QuestScene or SceneMap ?
Hi!
I think it should work., I mean, with the code you have shown.
JavaScript:
QuestScene.prototype.update = function () {
    // Maybe this had to have a Scene_something.prototype.update()
    if (Input.isTriggered('cancel')) {
        SceneManager.pop();
    }
}
If your scene is inherited from somewhere, I think that is what is being missed.



Yes, you can.

Where you are adding your window? To the QuestScene or SceneMap ?

I'm adding the windows to the QuestScene, and then I push it with the SceneManager. If I add what your comment suggested on QuestScene update function, I get an error 🙁

Well, I solved it by calling the update function for the Window inside the Scene update function. Don't know if that's the best practice for RM, but works good! Thank you, @Eliaquim
This is because you've overwritten the default update function of your scene but aren't calling the super in it, so all update is doing is whatever you've written. You need to preface your if statement with a call to the base class update function, same as you did with the window.

It's bad form to resolve this with what you've done, because there will still be other base update stuff that's not being done.
Maybe I did something wrong. I'll post my Scene and Windows in the current state:

JavaScript:
/** -----------------------------------------------------------
* Quest Scene
*/
function QuestScene() {
    this.initialize(...arguments);
}
QuestScene.prototype = Object.create(Scene_MenuBase.prototype);
QuestScene.prototype.constructor = QuestScene;
QuestScene.prototype.initialize = function () {
    Scene_MenuBase.prototype.initialize.call(this);
};
QuestScene.prototype.create = function (quest) {
    this.selectedQuest = quest;
    Scene_MenuBase.prototype.create.call(this);
  
    this.questListWindow = new QuestListWindow(
        new Rectangle(0, this.buttonAreaHeight(), Graphics.boxWidth / 3, Graphics.boxHeight - this.buttonAreaHeight()));
    this.questDetailsWindow = new QuestDetailWindow(
        new Rectangle(Graphics.boxWidth / 3, this.buttonAreaHeight(), (Graphics.boxWidth / 3) * 2, Graphics.boxHeight - this.buttonAreaHeight()));
    this.addWindow(this.questListWindow);
    this.addWindow(this.questDetailsWindow);
}
QuestScene.prototype.update = function () {
    if (Input.isTriggered('cancel')) {
        SceneManager.pop();
    }
    this.questListWindow.update(); // this is my workaround
    this.questDetailsWindow.update(this.selectedQuest); // this is my workaround
}
/** -----------------------------------------------------------
* Quest List Window
*/
function QuestListWindow() {
    this.initialize(...arguments);
}
QuestListWindow.prototype = Object.create(Window_Command.prototype);
QuestListWindow.prototype.constructor = QuestListWindow;
QuestListWindow.prototype.initialize = function (rect) {
    Window_Command.prototype.initialize.call(this, rect);
}
QuestListWindow.prototype.update = function () {
    Window_Command.prototype.update.call(this);
}
QuestListWindow.prototype.makeCommandList = function () {
    for(var i = 0; i <=20 ; i++) {
        this.addCommand("Yes", '');
    }
};

/** -----------------------------------------------------------
* Quest Detail Window
*/
function QuestDetailWindow() {
    this.initialize(...arguments);
}
QuestDetailWindow.prototype = Object.create(Window_Base.prototype);
QuestDetailWindow.prototype.constructor = QuestDetailWindow;
QuestDetailWindow.prototype.initialize = function (rect) {
    Window_Base.prototype.initialize.call(this, rect);
}
QuestDetailWindow.prototype.update = function (quest) {
    Window_Base.prototype.update.call(this);
    this.drawAllItems(quest);
}
QuestDetailWindow.prototype.drawAllItems = function () {
    this.drawText('Hello world', 0, 0);
}

As I said, it only happens when I override the update function on the Scene. If I delete that snippet, Windows get to update normally again.
This is because you've overwritten the default update function of your scene but aren't calling the super in it, so all update is doing is whatever you've written. You need to preface your if statement with a call to the base class update function, same as you did with the window.

It's bad form to resolve this with what you've done, because there will still be other base update stuff that's not being done.

You guys are awesome! I was calling Scene_MenuBase.prototype.update() instead of Scene_MenuBase.prototype.update.call(this). It worked like a charm! Thank you @Trihan and @Eliaquim !

Original thread: https://forums.rpgmakerweb.com/threads/about-scenes-and-windows-update-function.127583/