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,608
Reaction score
968
First Language
Portuguese - Br
Primarily Uses
RMMV
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,947
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 Posts

Latest Profile Posts

Woke up on an awful nightmare of being banned here because some mod didn't liked me in a super-heroes freeform round robin RP where I used throwing normal hammer as power and it was qualified being too OP. XD Nice to read you all guys. Will not wait next nightmares.
Staring at all the RPG Maker versions I have and realizing that my project has been a long time coming. But, I finally feel like I have the knowledge and experience to make it into something good.
We're almost done with the jam game! :D
I get scam calls all the time so today I gave them a piece of my mind. They hung up on me. Sweet revenge.

Forum statistics

Threads
104,320
Messages
1,005,550
Members
135,843
Latest member
xetyss
Top