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,673
Reaction score
1,084
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,955
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

rux
Just 80% of my motivation on game making lmao, anyone got tips on how to not be unmotivated?
I've signed up for a job training program for people with Asperger's Syndrome. I went to a "test run" today so they could see how well I did with simple jobs, and I amazed them. Most new people do it in 30+ minutes, while I finished in a mere 15 minutes. Gives me time to work on a screenplay for Studio MDHR...
People,I have seen that Someone from China/Chile and London is doing a Vaccine Against COVID-19.
Doing anything that yield good result in the long run is like sowing seeds. With proper care, they will grow and bear fruits. I'm excited for tomorrow. :D

Forum statistics

Threads
105,455
Messages
1,013,841
Members
137,105
Latest member
twilightprincess
Top