MV SceneManager.pop(); doesn't work for some reason?

Hi people on the forum,

I have been trying my hands at creating my own menu plugin, inspired by the Silent Hill Series,
but I have trouble understanding certain aspects of Javascript, since I'm a beginner at it.

This is what I want the menu to look like; (Sorry for the bad lighting, this is hand drawn).
Quick_mockup_game_psd (1)-compressed_page-0001.jpg


This is how the status window is shown in-game: it has the blurry background that the Main Menu usually has;
The menu is-game.jpg


This is the part of the code for exiting the scene: (I code in Notepad++)
Coding part 1.png


Here are the images of the rest of my code, if anyone can find a fault within it:
Coding part 2.png

Coding part 3.png


I need help with the exit of the Custom Menu screen and another question is how can I implement the Equip and Item menus in the coding?

Thank you for reading ~ EniaCat.
A couple of points:
  1. You're not invoking the update method from your scene's superclass, Scene_MenuBase. This means your scene literally only checks for input on its update cycle, and is otherwise static/unresponsive.

  2. It looks like you've defined the scene constructor after the update method? Define the constructor first, then its members.
So you could try something like this:
JavaScript:
/** @constructor */
function Scene_customMenu() {
  this.initialize.apply(this, arguments);
};

// Scene_customMenu methods...

Scene_customMenu.prototype.update = function() {
  Scene_MenuBase.prototype.update.call(this);
  if (Input.isTriggered("cancel")) SceneManager.pop();
};

To replace the pause menu with another scene, you could try this:
JavaScript:
Scene_Menu = Scene_customMenu;
Simpler and more likely to be compatible with other plugins than a Scene_Map#callMenu override~

You can go to the Equip/Item scenes via SceneManager.push(Scene_Equip) or SceneManager.push(Scene_Item) respectively.

If you want to have multiple interactive windows in your new scene, that's more complicated:
  • Add the relevant window(s) to your scene, e.g. Window_ItemList;
  • Add checks to manage when each window gains/loses focus, a.k.a. "active" status.
You can check out an existing scene's code to see an example of how this handling might be done, e.g. Scene_Menu or Scene_Equip in rpg_scenes.js.
Hi caethyril, thank you for your answer. The menu can close and open now, this is great!

The only thing now that I have trouble with is the multiple interactive windows.

For example:
If I add the [Window_ItemCategory] to the code then it works, but the moment I put in the
[Window_ItemList] into the code, the engine shows the window but after I picked up an item in-game, the engine doesnt recognize that I picked up the item.
(Because of this, I have to look around in the scene_item and scene_equip, but still no luck.)

Atleast I can close the menu now, that is a whole relief.

Thank you for the solution! If you can point me in the right direction for the multiple interactive windows, that would be great. Still I'm grateful for you help, thank you.
OK, here's an example from Scene_Item, comments mine:
Spoiler: Scene_Item window handling excerpts (rpg_scenes.js)
JavaScript:
// Add category window and assign ok/cancel handlers
Scene_Item.prototype.createCategoryWindow = function() {
    // Create new window instance, store reference on scene
    this._categoryWindow = new Window_ItemCategory();
    // Assign help window
    this._categoryWindow.setHelpWindow(this._helpWindow);
    this._categoryWindow.y = this._helpWindow.height;
    // On "ok", call the scene's onCategoryOk method (see below)
    this._categoryWindow.setHandler('ok',     this.onCategoryOk.bind(this));
    // On "cancel", pop the scene from the stack (i.e. return to previous scene)
    this._categoryWindow.setHandler('cancel', this.popScene.bind(this));
    // Add the window to the scene's window layer (display)
    this.addWindow(this._categoryWindow);
};

// Similarly for the item list...
Scene_Item.prototype.createItemWindow = function() {
    var wy = this._categoryWindow.y + this._categoryWindow.height;
    var wh = Graphics.boxHeight - wy;
    this._itemWindow = new Window_ItemList(0, wy, Graphics.boxWidth, wh);
    this._itemWindow.setHelpWindow(this._helpWindow);
    this._itemWindow.setHandler('ok',     this.onItemOk.bind(this));
    this._itemWindow.setHandler('cancel', this.onItemCancel.bind(this));
    this.addWindow(this._itemWindow);
    this._categoryWindow.setItemWindow(this._itemWindow);
};

// Switch focus to item list when a category is selected
Scene_Item.prototype.onCategoryOk = function() {
    this._itemWindow.activate();
    this._itemWindow.selectLast();
};

// Switch focus to the category list when item list is cancelled
Scene_Item.prototype.onItemCancel = function() {
    this._itemWindow.deselect();
    this._categoryWindow.activate();
};
I haven't shown the onItemOk code here, because it's not directly related to controlling which window is active. It's there, though, and it does what you'd expect.

Also, as you can see, the item scene exits based on a game window handler (category cancel) rather than having the scene itself check for a particular input.

Hopefully that helps! 👋
Hi caethyril, thank you for answering again.

I have tried in the coding but the engine doesn't show to the scene at all, but the console doesn't show anything.
the code in the scene_item part.png

I got the same result if I tried to put the code up above in the custom menu ->
the code in the Constructor part.png

I feel really confused, but I cannot seem to connect the item scene to the plugin.
I looked at different other menu plugins, but they keep the scene the same. Even online I couldn't really find a solution to connect the scenes.

EDIT: If I push the scene through the Console, it gives me:
Uncaught ReferenceError: Scene_CustomItem is not defined.

But I already thought that I defined it by calling the scene in the first place. I still don't get...
- EniaCat
I assume you'd want something like "select actor to see their items"? E.g. (untested):
JavaScript:
Scene_customMenu.prototype.create = function() {
  Scene_MenuBase.prototype.create.call(this);
  this._customWindow = new Window_customStatus(0, 0, 222, 222);
  this._customWindow.setHandler("ok", this.onActorOk.bind(this));
  this._customWindow.setHandler("cancel", this.popScene.bind(this));
  this.addWindow(this._customWindow);
};

Scene_customMenu.prototype.onActorOk = function() {
  SceneManager.push(Scene_CustomItem);
};

I'm not sure why you'd get the error you describe, I don't see any obvious mistakes in your code. If there were a syntax error in your plugin, that would prevent the plugin from being loaded, but would also show an error in the console. Did you close and relaunch the playtest after saving changes to your plugin file?

[Edit: corrected addHandler -> setHandler.]
I assume you'd want something like "select actor to see their items"? E.g. (untested):
JavaScript:
Scene_customMenu.prototype.create = function() {
  Scene_MenuBase.prototype.create.call(this);
  this._customWindow = new Window_customStatus(0, 0, 222, 222);
  this._customWindow.addHandler("ok", this.onActorOk.bind(this));
  this._customWindow.addHandler("cancel", this.popScene.bind(this));
  this.addWindow(this._customWindow);
};

Scene_customMenu.prototype.onActorOk = function() {
  SceneManager.push(Scene_CustomItem);
};

I'm not sure why you'd get the error you describe, I don't see any obvious mistakes in your code. If there were a syntax error in your plugin, that would prevent the plugin from being loaded, but would also show an error in the console. Did you close and relaunch the playtest after saving changes to your plugin file?
This is really weird, I did close and relaunch the playtest and the program after saving the changes, just in case.
but now I get this:
Screenshot 2022-07-19 002733.png


Why does javascript think addHandler is not a function?
Ah, that's my mistake: it should be setHandler. 😴

I'll correct my previous post~
Ah, that's my mistake: it should be setHandler. 😴

I'll correct my previous post~
Ah okay, no problem, I will try it out now.
I deactivated all my plugins just in case, so that my Menu is the only plugin that is on.
Screenshot 2022-07-19 012015.png

The console doesn't give anything.
Screenshot 2022-07-19 011941.png


EDIT:
If I put the SceneManager.push(Scene_customItem).
The Console says: cannot read property bind of undefined.
Screenshot 2022-07-19 012137.png

I looked into the code for a bit and it shows that the engine cannot read the

this.createItemWindow();
and
this._itemWindow.setHandler('ok', this.onItemOk.bind(this)); this._itemWindow.setHandler('cancel', this.onItemCancel.bind(this));

Hopefully you can find a solution for this.
- EniaCat
The problem is that you have tried to call Function#bind on Scene_customItem#onItemOk. But like the error message says, that method is undefined, i.e. Scene_customItem has no property named onItemOk. (Or at least, I don't see one in your screenshots.) In case you don't know what bind is for:

😅 If you're struggling this much then maybe it would be a good idea to take some time to study JavaScript before continuing? I'm not going to lead you through everything required to create your custom scene, and it would be much better for you to understand what's going on anyway. 👋

For example, here's a "first steps" tutorial:
Here's an error reference, to better understand what the errors mean:
There are other sites, too, e.g.
Hi Caethyril, I want to say first thank you for help and information, it really helped me a lot.
I guess I need to study more. 😀👍
Thank you for the links, I will look right into it.
It is indeed better if I do it myself through trial and error. :blush:
Then I can identify those errors myself. But you have been a great help. So I want to thank you personally. 😎👍

I don't really know how to close a thread, though... >_>
- EniaCat
No worries!

On these boards, if you want a thread closed, you can click the Report button on your own post with a reason like "Solved" or "This can be closed". That highlights it for the moderators, who can close the thread.

Since I'm here now, though:

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.

Original thread: https://forums.rpgmakerweb.com/threads/scenemanager-pop-doesnt-work-for-some-reason.149539/