RMMZ About Scenes and Windows update function...

PMantis13

Caipirinha lover.
Veteran
Joined
Aug 29, 2020
Messages
31
Reaction score
18
First Language
PT-BR
Primarily Uses
RMMZ
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.
 

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,678
Reaction score
1,095
First Language
Portuguese - Br
Primarily Uses
RMMZ
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 ?
 

PMantis13

Caipirinha lover.
Veteran
Joined
Aug 29, 2020
Messages
31
Reaction score
18
First Language
PT-BR
Primarily Uses
RMMZ
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
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,604
Reaction score
1,956
First Language
English
Primarily Uses
RMMV
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.
 

PMantis13

Caipirinha lover.
Veteran
Joined
Aug 29, 2020
Messages
31
Reaction score
18
First Language
PT-BR
Primarily Uses
RMMZ
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.
 
Last edited:

PMantis13

Caipirinha lover.
Veteran
Joined
Aug 29, 2020
Messages
31
Reaction score
18
First Language
PT-BR
Primarily Uses
RMMZ
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 !
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

So I'm practicing ITC with a spirit box, and decide to try to contact my deceased soulmate. It actually gave me multiple identifiers. Me, still a bit skeptical, asked aloud "Fine but does he still love me?" and the box spoke and printed the word "Forever" at the same time. Been a mess of tears since. :kaocry:
Been scratching away at my game and making progress, but just had a revelation. I'm working in full screen and adjusting all my pictures accordingly, but will they resize if someone's screen is smaller?? I hope this doesn't turn out to be a problem later.
Why is there so much month left at the end of money? D=
Hello humans! How goes your day in this journey of living? I hope it is good, for I am human like you, and I am feeling great! Worship the altar.

Forum statistics

Threads
105,628
Messages
1,015,076
Members
137,288
Latest member
GmOcean
Top