MZ Basic guide for creating new scenes in MZ?

Hiya folks. Im trying to develop my own scene to handle some unique input. I want to make something like what you see below, where the user can click on drawn areas to plot a course for travel. The logic is easy enough to design, but creating a blank new scene to start drawing on and then adding windows to it has been a bit of a challenge.

can someone help walk a newbie through creating a bare bones scene, and adding a new barebones window to it? I've tried to reverse engineer the process, but the plug-ins I find have a ton of moving pieces. TravelSystem - Page 5.png
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
  }
}

For the prototype approach:

JavaScript:
function Window_OMGPMenu() {
  this.initialize(...arguments);
}

Window_OMGPMenu.prototype = Object.create(Window_Command.prototype);
Window_OMGPMenu.prototype.constructor = Window_OMGPMenu;

Window_OMGPMenu.prototype.initialize = function(rect) {
  Window_Command.prototype.initialize.call(this, rect);
};

Window_OMGPMenu.prototype.makeCommandList = function() {
  this.addCommand("Travel", "travel");
  this.addCommand("Menu", "menu");
  this.addCommand("Cancel", "cancel");
};

function Scene_OMGPMenu() {
  this.initialize(...arguments);
}

Scene_OMGPMenu.prototype = Object.create(Scene_Base.prototype);
Scene_OMGPMenu.prototype.constructor = Scene_OMGPMenu;

Scene_OMGPMenu.prototype.initialize = function() {
  Scene_Base.prototype.initialize.call(this);
};

Scene_OMGPMenu.prototype.create = function() {
  Scene_Base.prototype.create.call(this);
  this.createMenuWindow();
};

Scene_OMGPMenu.prototype.createMenuWindow = function() {
  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);
};

Scene_OMGPMenu.prototype.menuWindowRect = function() {
  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);
};

Scene_OMGPMenu.prototype.commandTravel = function() {
  // Implementation of travel command here
};

Scene_OMGPMenu.prototype.commandMenu = function() {
  // Implementation of menu command here
};

That's the minimum required to have a scene you can transition to with a window that has your commands in it.
That 1st one I understand completely. Thanks a million bud!
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
  }
}

For the prototype approach:

JavaScript:
function Window_OMGPMenu() {
  this.initialize(...arguments);
}

Window_OMGPMenu.prototype = Object.create(Window_Command.prototype);
Window_OMGPMenu.prototype.constructor = Window_OMGPMenu;

Window_OMGPMenu.prototype.initialize = function(rect) {
  Window_Command.prototype.initialize.call(this, rect);
};

Window_OMGPMenu.prototype.makeCommandList = function() {
  this.addCommand("Travel", "travel");
  this.addCommand("Menu", "menu");
  this.addCommand("Cancel", "cancel");
};

function Scene_OMGPMenu() {
  this.initialize(...arguments);
}

Scene_OMGPMenu.prototype = Object.create(Scene_Base.prototype);
Scene_OMGPMenu.prototype.constructor = Scene_OMGPMenu;

Scene_OMGPMenu.prototype.initialize = function() {
  Scene_Base.prototype.initialize.call(this);
};

Scene_OMGPMenu.prototype.create = function() {
  Scene_Base.prototype.create.call(this);
  this.createMenuWindow();
};

Scene_OMGPMenu.prototype.createMenuWindow = function() {
  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);
};

Scene_OMGPMenu.prototype.menuWindowRect = function() {
  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);
};

Scene_OMGPMenu.prototype.commandTravel = function() {
  // Implementation of travel command here
};

Scene_OMGPMenu.prototype.commandMenu = function() {
  // Implementation of menu command here
};

That's the minimum required to have a scene you can transition to with a window that has your commands in it.
The ES6 method still uses the basic Scene_Manager.push(♤), Scene_Manager.PrepareNext(), right?
The ES6 method still uses the basic Scene_Manager.push(♤), Scene_Manager.PrepareNext(), right?
SceneManager, but yes, that doesn't change. The class notation is mainly syntactic sugar rather than an actual implementation of classes the way languages like C# represent them.
Seriously, thank you. I come from the Java world initially. Prototyping hurts my soul. I'm just trying to practice my JS between clients.
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
    }
}
1678157362204.png
Hi there!

Firstly, I don't think super() call outside of a constructor is legal.
You can use it outside the constructor, but you need to call the method too:

JavaScript:
create(){
    super.create()
    // your code
}

//The above is equivalent to the below:
const alias = Scene_Base_create
Scene_Base.prototype.create = function(){
    Scene_Base_create.call(this) // super.create()
    // your code
}
I think I *might* have known that... but in my desperate attempts to debug, I found that just switching to constructors was more reliable with my own bad coding 😅

Thank you for sharing though. I'm sure I can't be the only person riding the struggle bus on this concept.
Hi there!


You can use it outside the constructor, but you need to call the method too:

JavaScript:
create(){
    super.create()
    // your code
}

//The above is equivalent to the below:
const alias = Scene_Base_create
Scene_Base.prototype.create = function(){
    Scene_Base_create.call(this) // super.create()
    // your code
}
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
    }
}
View attachment 255305
Yeah, that was me forgetting to put super.create(); and to pass the rect parameter to the window constructor. Sorry about that!

Original thread: https://forums.rpgmakerweb.com/threads/basic-guide-for-creating-new-scenes-in-mz.155588/