There are two approaches to this: ES6 class notation or the prototype notation used by the default engine. I'll outline both:
JavaScript:
class Window_OMGPMenu extends Window_Command {
makeCommandList() {
this.addCommand("Travel", "travel");
this.addCommand("Menu", "menu");
this.addCommand("Cancel", "cancel");
}
}
class Scene_OMGPMenu extends Scene_Base {
create() {
super();
this.createMenuWindow();
}
createMenuWindow() {
const rect = this.menuWindowRect();
this._menuWindow = new Window_OMGPMenu();
this._menuWindow.setHandler("travel", this.commandTravel.bind(this));
this._menuWindow.setHandler("menu", this.commandMenu.bind(this));
this._menuWindow.setHandler("cancel", this.popScene.bind(this));
this.addWindow(this._menuWindow);
}
menuWindowRect() {
const ww = this.mainCommandWidth();
const wh = this.calcWindowHeight(3, true);
const wx = Graphics.boxWidth - this.mainCommandWidth();
const wy = 0;
return new Rectangle(wx, wy, ww, wh);
}
commandTravel() {
// Implementation of travel command here
}
commandMenu() {
// Implementation of menu command here
}
}
Okay, maybe I'm just dumb... but I think there's two issues with the ES6 implementation as is.
Firstly, I don't think super() call outside of a constructor is legal. Secondly, the value of `const rec` isn't used anywhere. I think this is the source of the error I'm getting. It's entirely possible that the issue is one of compatibility.
The error:
Code:
rmmz_managers.js:2032 SyntaxError: Unexpected token u in JSON at position 0
at JSON.parse (<anonymous>)
at Function.JsonEx.parse (rmmz_core.js:6389)
at Function.JsonEx.makeDeepCopy (rmmz_core.js:6399)
at Window_OMGPMenu.Window_Base.<computed> [as registerResetRect] (VisuMZ_1_MessageCore.js:2314)
at Window_OMGPMenu.Window_Base.<computed>.<computed> [as initMessageCore] (VisuMZ_1_MessageCore.js:2314)
at Window_OMGPMenu.Window_Base.<computed>.<computed> [as initialize] (VisuMZ_1_MessageCore.js:2314)
at Window_OMGPMenu.Window_Scrollable.initialize (rmmz_windows.js:606)
at Window_OMGPMenu.Window_Selectable.initialize (rmmz_windows.js:852)
at Window_OMGPMenu.Window_Selectable.<computed>.initialize (VisuMZ_1_ItemsEquipsCore.js:3056)
at Window_OMGPMenu.Window_Command.initialize (rmmz_windows.js:1463
Edit: I solved the issue. I deleted create() and just used constructor() instead. No muss no fuss. I added rect as a parameter that got passed via constructor() to super(). And then finally, I added this.createWindowLayer() to the create menu function. Between these three edits, the world is saved.
"Final Code" for a working example for the next girl wondering how to do it."
Code:
class Window_OMGPMenu extends Window_Command {
constructor(rect) {
super(rect)
}
makeCommandList() {
this.addCommand("Travel", "travel");
this.addCommand("Menu", "menu");
this.addCommand("Cancel", "cancel");
}
}
class Scene_PocketsTravelSystem extends Scene_Base {
constructor() {
super();
this.createMenuWindow();
}
createMenuWindow() {
const rect = this.menuWindowRect();
this._menuWindow = new Window_OMGPMenu(rect);
this._menuWindow.setHandler("travel", this.commandTravel.bind(this));
this._menuWindow.setHandler("menu", this.commandMenu.bind(this));
this._menuWindow.setHandler("cancel", this.popScene.bind(this));
this.createWindowLayer();
this.addWindow(this._menuWindow);
}
menuWindowRect() {
const ww = this.mainCommandWidth();
const wh = this.calcWindowHeight(3, true);
const wx = Graphics.boxWidth - this.mainCommandWidth();
const wy = 0;
return new Rectangle(wx, wy, ww, wh);
}
commandTravel() {
// Implementation of travel command here
}
commandMenu() {
// Implementation of travel command here
}
}