Can't figure out what's wrong here

Status
Not open for further replies.

TragicNumberOne

Veteran
Veteran
Joined
Feb 9, 2018
Messages
32
Reaction score
3
First Language
English
Primarily Uses
RMMV
Howdy!

After some help with menus, I though I had a good understanding of them, however, this is clearly not the case so here I am.

My goal is just to make a window popup with text. Right now the error comes up when I try to create the window.

Here's my error and code:

Code:
TypeError: Cannot read property 'addChild' of undefined
Code:
//There is no need for this to be declared becasue the interpreterCommand from ResistanceIsFeudalGameStart.
//var interpreterCommand = Game_Interpreter.prototype.pluginCommand;

Game_Interpreter.prototype.pluginCommand = function(command, args) {
    interpreterCommand.apply(this);
    if (command === 'endScreen') {
        Scene_Map.prototype.createEndWindow();
    };
};

Scene_Map.prototype.createEndWindow = function() {
    this._endWindow = new Window_End(0, 0);
    this._endWindow.x = 10;
    this._endWindow.y = 10;
    //if (true) {
        this._endWindow.drawText ("Ending 1 text", 0, 0, 0, 'left' );
    //}
    Scene_Base.prototype.addWindow(this._endWindow);
};

function Window_End() {
    this.initialize.apply(this, arguments);
};

Window_End.prototype = Object.create(Window_Base.prototype);
Window_End.prototype.constructor = Window_End;

Window_End.prototype.initialize = function(x, y) {  
    var width = this.windowWidth();
    var Height = this.windowHeight();
    Window_Base.prototype.initialize.call(this, x, y, width, Height);
};

Window_End.prototype.windowWidth = function() {
    return Graphics.boxWidth - 20;
};

Window_End.prototype.windowHeight = function() {
    return Graphics.boxHeight - 20;
};
Thanks for helping!
 

Aloe Guvner

Walrus
Veteran
Joined
Sep 28, 2017
Messages
1,628
Reaction score
1,115
First Language
English
Primarily Uses
RMMV
A comment unrelated to your question:
  • The way you have overwritten the Game_Interpreter.prototype.pluginCommand function will break plugin commands from all other plugins above it because you're not applying the arguments to the alias.
On to your question:

There's an important difference between a Constructor and an Instance that is useful to understand.
Scene_Map is the constructor for the map scene, but it is not the actual object that is being run during the game. Similar to how your Window_End is a constructor. What appears in the game is an instance of the constructor created with the "new" keyword.

So the plugin command should call the createEndWindow method of the actual scene, rather than the scene constructor.

Code:
Scene_Map.prototype.createEndWindow();
//should be replaced with
SceneManager._scene.createEndWindow();
Code:
Scene_Base.prototype.addWindow(this._endWindow);
//should be replaced with
this.addWindow(this._endWindow);
 

TragicNumberOne

Veteran
Veteran
Joined
Feb 9, 2018
Messages
32
Reaction score
3
First Language
English
Primarily Uses
RMMV
A comment unrelated to your question:
  • The way you have overwritten the Game_Interpreter.prototype.pluginCommand function will break plugin commands from all other plugins above it because you're not applying the arguments to the alias.
On to your question:

There's an important difference between a Constructor and an Instance that is useful to understand.
Scene_Map is the constructor for the map scene, but it is not the actual object that is being run during the game. Similar to how your Window_End is a constructor. What appears in the game is an instance of the constructor created with the "new" keyword.

So the plugin command should call the createEndWindow method of the actual scene, rather than the scene constructor.

Code:
Scene_Map.prototype.createEndWindow();
//should be replaced with
SceneManager._scene.createEndWindow();
Code:
Scene_Base.prototype.addWindow(this._endWindow);
//should be replaced with
this.addWindow(this._endWindow);
Howdy, thanks for the response. I actually solved the issue using a workaround, and have tried to close the thread, but you seem to have hit on something else with the first part of your response. The new code looks like this if you're interested. I think that this new code solves both problems:
Code:
Scene_Map.prototype.update = function() {
    _Scene_Map_update.call(this);
    if ($gameSwitches.value(6)) {
        $gameSwitches.setValue(6, false);
        this.createEndWindow();
    }
};

Scene_Map.prototype.createEndWindow = function() {
    this._endWindow = new Window_End(0, 0);
    this._endWindow.x = 10;
    this._endWindow.y = 10;
    //if (true) {
        this._endWindow.drawText ("Ending 1 text", 0, 0, 0, 'left' );
    //}
    this.addWindow(this._endWindow);
};

function Window_End() {
    this.initialize.apply(this, arguments);
};

Window_End.prototype = Object.create(Window_Base.prototype);
Window_End.prototype.constructor = Window_End;

Window_End.prototype.initialize = function(x, y) {
    var width = this.windowWidth();
    var Height = this.windowHeight();
    Window_Base.prototype.initialize.call(this, x, y, width, Height);
};

Window_End.prototype.windowWidth = function() {
    return Graphics.boxWidth - 20;
};

Window_End.prototype.windowHeight = function() {
    return Graphics.boxHeight - 20;
};
The reason why the first attempt was done like that was because I was trying to create a solution using plugin commands and couldn't figure out why it didn't work; this lead to a domino effect of increasingly zany attempted fixes. However, this new system of flags getting checked on update seems to be smoother (if less efficient.)
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,713
First Language
English
Primarily Uses
RMVXA
@TragicNumberOne I've seen your Report asking for this to be closed, but I am now unclear whether this new development means that you want to keep it open to continue the conversation with Aloe Guvner. I am, therefore, taking no action at this point. When you are sure that you want the thread closed, please Report it again.
 

TragicNumberOne

Veteran
Veteran
Joined
Feb 9, 2018
Messages
32
Reaction score
3
First Language
English
Primarily Uses
RMMV
@TragicNumberOne I've seen your Report asking for this to be closed, but I am now unclear whether this new development means that you want to keep it open to continue the conversation with Aloe Guvner. I am, therefore, taking no action at this point. When you are sure that you want the thread closed, please Report it again.
Thanks! He responded after I sent the report, so I was unsure if you would notice.
 

Aloe Guvner

Walrus
Veteran
Joined
Sep 28, 2017
Messages
1,628
Reaction score
1,115
First Language
English
Primarily Uses
RMMV
Looks good now! From just reading it, I believe it would work fine.

I see that you are using switch #6 inside the 'update' method in order to create the window. Presumably, some event on the map is turning switch #6 to ON. The thing is that the 'update' method runs every single frame, so 60x per second, continuously checking if the switch is ON. Although it's not likely to cause any noticeable lag, I would suggest one improvement:

  1. Alias the 'Scene_Map.prototype.createAllWindows' method and call your 'createEndWindow' from inside there
  2. Add a line to the end of your 'Window_End.prototype.initialize' method with "this.hide();"
  3. In your event on the map instead of turning switch #6 on, do a script call of "SceneManager._scene._endWindow.show();"
The benefits of doing it this way - you run the code on-demand rather than 60x per second, and you don't have to consume a switch.
 

TragicNumberOne

Veteran
Veteran
Joined
Feb 9, 2018
Messages
32
Reaction score
3
First Language
English
Primarily Uses
RMMV
Looks good now! From just reading it, I believe it would work fine.

I see that you are using switch #6 inside the 'update' method in order to create the window. Presumably, some event on the map is turning switch #6 to ON. The thing is that the 'update' method runs every single frame, so 60x per second, continuously checking if the switch is ON. Although it's not likely to cause any noticeable lag, I would suggest one improvement:

  1. Alias the 'Scene_Map.prototype.createAllWindows' method and call your 'createEndWindow' from inside there
  2. Add a line to the end of your 'Window_End.prototype.initialize' method with "this.hide();"
  3. In your event on the map instead of turning switch #6 on, do a script call of "SceneManager._scene._endWindow.show();"
The benefits of doing it this way - you run the code on-demand rather than 60x per second, and you don't have to consume a switch.
Thanks for the advice, I'll try to implement these changes.

As always thanks for help!
 

mlogan

Global Moderators
Global Mod
Joined
Mar 18, 2012
Messages
15,377
Reaction score
8,536
First Language
English
Primarily Uses
RMMV

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

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

Latest Threads

Latest Profile Posts

Day 9 of giveaways! 8 prizes today :D
He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.

Forum statistics

Threads
106,040
Messages
1,018,476
Members
137,824
Latest member
dobratemporal
Top