Learning to make menus

I'm trying to learn how to create new menus, in the sense of "select whether this character is male or female." But I'm having trouble finding a tutorial for it because my searches keep turning up tutorials for changing the look/layout of existing menus instead. I've also tried looking at code, but there's a lot going on in there at once and there's no real help from comments.

Does anyone know of a good tutorial for this sort of thing, or a simple example plugin with helpful comments?
You don't need a plugin. Just a series of Text dialogues with Choices afterwards, and either set switches or run commands to change your actors based on the results.

If you want more specific help, you'll need to indicate how many choices you're going to give the player (are you JUST letting them choose gender, or are you letting them choose class or other things as well?)

And don't make the mistake of setting up one actor in the database for every possible combination. Have one actor for each party member, and use the Change Actor ... commands to alter them based on the player's choices.
You don't need a plugin.

I'm writing my own.


Just a series of Text dialogues with Choices afterwards, and either set switches or run commands to change your actors based on the results.

I could do that, but a simple menu would be a much cleaner and more robust way of doing the job. And knowing how to set that up could be useful elsewhere.

If you want more specific help, you'll need to indicate how many choices you're going to give the player (are you JUST letting them choose gender, or are you letting them choose class or other things as well?)

Choosing gender was just the simplest example of the principle that I could think of. The idea is to have a pool of states that can be chosen from (for actors) or assigned randomly (for enemies). I've already figured out how to assign them randomly, so I've got most of what I need. I just don't understand how menus are set up in code. If I can figure that out I'm pretty sure I can handle the rest.
So are you asking for help writing your plugin then? You didn't mention that in your OP, and you didn't post in the Javascript Support forum.
No, I'm asking for a simple demonstration of how to set up a new menu in code. A plugin might do if the documentation explains what's going on, but a text/video tutorial is also fine. Just something better than trying to trace my way through a bunch of uncommented code.


EDIT: Actually, now that I think about it that DOES sound like what you meant. Which means this is in the wrong forum. Sorry.
Moved to: Javascript Plugin Support
Dunno if this is exactly what you need but I hope it helps.

Spoiler: Source
Code:
function customMenu() {
    "use strict";

    // Step 1: Create an object based on the type of window we need. Windows are
    //         listed in rpg_windows.js so you can read up on what methods and
    //         properties Window_Command.prototype has and that it also inherits
    //         stuff from Window_Base.prototype.

    var window = Object.create(Window_Command.prototype);

    // Step 2: Override and/or alias methods of the new object and set desired
    //         properties. For this example we'll change the width and height of
    //         the new window.

    window.windowWidth = function () {
        return 200;
    };

    window.windowHeight = function () {
        return 109;
    };

    // Step 3: Setup the list of commands. This just creates the text for the
    //         menu. Selecting/clicking the menu items does nothing yet.

    window.makeCommandList = function () {

    // The addCommand() method takes 2 arguments at minimum. The first is the
    // text for the command and the 2nd is for the symbol. The symbol is used to
    // assign a handler function to be invoked when the command is activated.

        window.addCommand("Male", "male");
        window.addCommand("Female", "female");
    };

    /**
     * Step 4: Call the initialize method. It takes two parameters.
     * @param {number} x The position of the window from the left edge of
     *                   the screen.
     * @param {number} y The position of the window from the top of the screen.
     */
    window.initialize(0, 0);

    /**
     * Step 5: Setup the handlers for each menu item. Two parameters per menu
     *         item. Gonna need the console open to see the results for
     *         the demo.
     * @param {string} symbol The symbol argument we used with addCommand().
     * @param {function} callback The function to invoke to handle the event.
     */
    window.setHandler("male", function () {
        console.log("You clicked male.");

        // Selecting an item from the list causes the window to deactivate so
        // we'll invoke the activate() method for demo purposes.

        window.activate();
    });

    window.setHandler("female", function () {
        console.log("You clicked female.");
        window.activate();
    });

    window.setHandler("cancel", function () {

        // Remove the scene. The game will go back to the previous scene when
        // the user presses the ESC key or left mouse button.

        SceneManager._scene.popScene();
    });

    // Final Step: Give the new window object to the caller.
 
    return window;
}

// This line of code will add the window to the current scene but there will
// be problems. The characters will still obey directional input for example. I
// imagine there's a way to fix it but I haven't looked into it.

// SceneManager._scene.addWindow(customMenu());

// It's probably better to create a new scene and attach your windows to that.

function customMenuScene() {
    "use strict";

    // Create the scene.

    var scene = Object.create(Scene_MenuBase.prototype);

    // Alias the create() method so we can add our customMenu to the scene.
 
    scene.create = (function (alias) {
        function create() {
            alias.call(scene);
            scene.addWindow(customMenu());
        }
 
        return create;
    }(scene.create));

    // Scenes must be initialized before we return.

    scene.initialize();
 
    return scene;
}

// This line of code will activate the new scene.

// SceneManager.push(customMenuScene);
It helps me understand the basic structure, yes. Thanks. But when I tried to test your code it didn't work. Using "SceneManager._scene.addWindow(customMenu());" or "SceneManager.push(customMenuScene);" gives an error saying that customMenu/customMenuScene isn't defined.

EDIT: Before you ask: I made a plugin out of it and set up an event to run the command when activated. Yes, the plugin was loaded without errors.
Here's an example project.
Did you change any of the code? Your sample project works, but it looks like you just did the same thing I did so I don't understand why mine crashed.
I copied the code from my initial post and put that into a project with minimum assets to keep the download small. Dunno why it didn't work right off the bat for you.
Oh, well. Gremlins in the code, I guess.

Anyway, I should be able to figure it out from here. Thanks, that was a big help.

Original thread: https://forums.rpgmakerweb.com/threads/learning-to-make-menus.79707/