MZ Remove Main Menu Options - Which Option Is Better For .JS Plugin?

I posted this here, because it didn't seem to fit in the categories of the JS Plugins section. But I could be wrong.

I want to remove a few options from the Main Menu Options. I searched for information, found an example of removing certain volume options, I opened the rmmz_windows .js file, and located what I think is the correct information that needs to be modified.

I want to remove the Always Dash, Command Remember, and Touch UI options, but keep the volume options.

I was planning on making a new .js plugin to modify the Main Menu Options window. I think this is the relevant code:

Window_Options.prototype.makeCommandList = function() {
this.addGeneralOptions();
this.addVolumeOptions();
};

Window_Options.prototype.addGeneralOptions = function() {
this.addCommand(TextManager.alwaysDash, "alwaysDash");
this.addCommand(TextManager.commandRemember, "commandRemember");
this.addCommand(TextManager.touchUI, "touchUI");
};

I saw in a related thread that I should just be able to do something like this:

Window_Options.prototype.makeCommandList = function() {
//this.addGeneralOptions();
this.addVolumeOptions();
};
OR

Window_Options.prototype.addGeneralOptions = function() {
//this.addCommand(TextManager.alwaysDash, "alwaysDash");
// this.addCommand(TextManager.commandRemember, "commandRemember");
// this.addCommand(TextManager.touchUI, "touchUI");

};

I think by adding the "//" you are making this a Comment so those options won't be added. Or, since it is a plugin, those options will be removed.

If that is correct, which is better?

Edit the first function - "//this.addGeneralOptions();"? Since that seems like it would remove all of the general options?

Or Edit the second function with each of the 3 general options listed?

I would think it would be better to just use this is the plugin:

Window_Options.prototype.makeCommandList = function() {
//this.addGeneralOptions();
this.addVolumeOptions();

};

But I wanted to make sure this was correct and wouldn't cause any unforeseen problems.

Also, I think this needs to be added at the beginning of the plugin:

/*:
* @target MZ
* @plugindesc Remove General Options From Main Menu Options
* @Help Free to use and/or modify for any project, no credit required.
*/

But I also wanted to check that. I am not plugin conversant.

Thanks for any assistance you can provide!
If you want to ensure compatibility you could do something like this:
JavaScript:
_Window_Options_addGeneralOptions = Window_Options.prototype.addGeneralOptions;
Window_Options.prototype.addGeneralOptions = function() {
    _Window_Options_addGeneralOptions.call(this);
    const dashCmd = this._list.find(item => item && item.symbol === "alwaysDash");
    const rembCmd = this._list.find(item => item && item.symbol === "commandRemember");
    const tochCmd = this._list.find(item => item && item.symbol === "touchUI");
    this._list.remove(dashCmd);
    this._list.remove(rembCmd);
    this._list.remove(tochCmd);
};
if you really dont need them and for personal use, I would simply do
JavaScript:
Window_Options.prototype.addGeneralOptions = function() {}

Window_Options.prototype.makeCommandList = function() {
//this.addGeneralOptions();
this.addVolumeOptions();
};

or do :
Window_Options.prototype.addGeneralOptions = function() {
/*this.addCommand(TextManager.alwaysDash, "alwaysDash");
this.addCommand(TextManager.commandRemember, "commandRemember");
 this.addCommand(TextManager.touchUI, "touchUI"); */
};

but it depends what you need for your game.

less code is better than a work around.
but comment it out is easy way back in if you change your mind.
@TobyYasha Thanks for that! I won't be using very many plugins, but compatibility is always something that should be considered!

I don't understand what all of that is doing, but I can clearly see where the options are being removed.


@ShadowDragon Thanks! Your response to a related thread was what got me looking for how to do this.

What is the [ B ] doing? Especially in your first example? I see the //Comment part, but I don't understand why the is necessary there since I have no idea what it is doing.


This is for my Sudoku game so I definitely won't need these options at all.

Thanks for giving me options to try!
Here's an explanation of what the code is doing:
JavaScript:
// Here we have the method create the general options
Window_Options.prototype.addGeneralOptions = function() {
    // The method below creates a command with the following arguments:

    // TextManager.alwaysDash - This is the name of the option found in the database
    // "alwaysDash" - This is an unique identifier for this command

    this.addCommand(TextManager.alwaysDash, "alwaysDash");
};

// When we create a command its data is stored in an array
// Do note that the stored data is an object in this case
Window_Command.prototype.addCommand = function(
    name, symbol, enabled = true, ext = null
) {
    this._list.push({ name: name, symbol: symbol, enabled: enabled, ext: ext });
};

// Since "this._list" is an array that means we have access to array methods
_Window_Options_addGeneralOptions = Window_Options.prototype.addGeneralOptions;
Window_Options.prototype.addGeneralOptions = function() {
    _Window_Options_addGeneralOptions.call(this);
    // Check if there's a valid item(not null or undefined) with the symbol property
    // NOTE: In this case we're looking for the "Always Dash" command.

    // As we've seen before when we create a command we also give it a unique identifier
    // which is stored in the "symbol" property.

    // NOTE: Don't confuse the "name" property with the "symbol" property they are
    // not the same thing even if they may look like it.

    const dashCmd = this._list.find(item => item && item.symbol === "alwaysDash");

    // If we've found the "Always Dash" command then we can remove it!
    this._list.remove(dashCmd);
};
@TobyYasha Thanks for taking the time to explain this! I can't say I 100% understand everything, but the more I refer to it and the more I learn, the easier it gets!
Removing the entire "general options" category is quite easy, like ShadowDragon said:
JavaScript:
Window_Options.prototype.addGeneralOptions = function() {}
Note that if a plugin loads after this one, it may override/patch this method to add new stuff.

Personally, to skip adding specific commands, I patch addCommand, e.g.
JavaScript:
// In a local function to avoid polluting the global scope.
;void (() => {
'use strict';  // Optional: be a little stricter with code interpretation.

  // Symbols of commands that should not be added.
  const SKIP = Object.freeze(["alwaysDash", "commandRemember", "touchUI"]);

  // Store method as it is.
  const aliasA = Window_Options.prototype.addCommand;
  // Redefine method.
  Window_Options.prototype.addCommand = function(name, symbol, enabled, ext) {
    // If command symbol is not in the "skip" list...
    if (!SKIP.includes(symbol))
      aliasA.apply(this, arguments);  // ...then add it as usual.
  };

  // And another patch (MZ) to ensure the options window is sized correctly.
  const aliasB = Scene_Options.prototype.maxCommands;
  Scene_Options.prototype.maxCommands = function() {
    return aliasB.apply(this, arguments) - SKIP.length;
  };

})();
Personally, to skip adding specific commands, I patch addCommand, e.g.
I didn't know freeze was a thing, but defenitely cleaner as this works in MV too
or is it slightly different?


What is the [ B ] doing?
that is a mistake of the "Bold text" and can be ignored.
@caethyril Thanks! I actually missed the first example in ShadowDragon's response!

And I appreciate the option of changing the size of the window. I thought about that, but hadn't gotten around to searching for anything about it.

@ShadowDragon Ha! I noticed that my response fell afoul of the [ B ] thing! That is why I edited my response to put the spaces.

This is very cool because it gives me different things to experiment with and try to better understand what is happening.
I would go with @caethyril answer because you can increase the array
if some others add more stuff and you can easely skip the command 🙂

but use whatever you need and works best for you, as caethyril answer
keep the function active and cannot be overwritten, so its also much safer.
I didn't know freeze was a thing, but defenitely cleaner as this works in MV too or is it slightly different?
It works in MV. But the freeze() doesn't actually have anything to do with the process that @caethyril demonstrated for removing commands. You could use a regular array of strings to compare the command symbols.

The freeze() portion is just syntactically reinforcing the const declaration of the SKIP variable, saying "this should never be changed during runtime".

I posted this here, because it didn't seem to fit in the categories of the JS Plugins section. But I could be wrong.
It's not a plugin, so it doesn't go in JS Plugins. But it is asking questions about JavaScript, so it would go in Learning JavaScript.
I just noticed you also asked about the header:
Also, I think this needs to be added at the beginning of the plugin:

/*:
* @target MZ
* @plugindesc Remove General Options From Main Menu Options
* @Help Free to use and/or modify for any project, no credit required.
*/
This is correctly-formatted. The header is just information used by the Plugin Manager, so it is not strictly essential. It's a nice touch, though, and easy enough to add!
  • @target MZ - this suppresses the "plugin may not be written for MZ" warning.
  • @plugindesc - this is the short summary, e.g. seen in the active plugin list.
  • @help - this is the long description, e.g. seen when editing the plugin's params.
@help is commonly used for instructions and terms of use, like you have there. You might also want:
  • @author ZombieKidzRule - shows in the plugin's author field.
  • @url https://forums.rpgmakerweb.com/threads/167939/ - a clickable URL (MZ).
There are other directives available, e.g. for parameters, plugin commands, and localisation. These are documented here in Japanese; for an English version, check out the "Explanation about Annotations" section of the MZ Plugin Creation Tutorial, or the "Plugin Header" section at the bottom of the main sheet of the Script Call List.

I didn't know freeze was a thing, but defenitely cleaner as this works in MV too
or is it slightly different?
Like Turan says, freezing an object makes its top-level properties non-configurable, i.e. read-only. Here, it means that we can't add/remove/edit command symbols in the local constant SKIP after it is declared. (const just means we can't reassign the variable: it doesn't prevent sub-properties from being changed.) That allows the compiler to do things like replace SKIP.length with 3 or whatever it might be, rather than potentially having to check the array length each call. (Compilers are smart, though: that optimisation might get applied regardless.)

Object.freeze and use strict (i.e. strict mode) can change a typo or logic mistake into an obvious error. They should not otherwise affect the final result: they're tools that let a programmer clarify their intent. I believe they're both ES5, in which case they should work even in older versions of MV.

Edit: good point, there are a bunch of related threads pinned in Learning JS.

I've moved this thread to Learning JavaScript (from MZ Support). Thank you.

@caethyril I tried your suggested code and it seems to work perfectly! Thanks!

Thanks to everyone who responded with options to try!

I hope this helps someone else who ends up looking for something like this.

I will give this another day in case anyone wants to add anything and then I will ask that the thread be closed.

You all are awesome!

Original thread: https://forums.rpgmakerweb.com/threads/remove-main-menu-options-which-option-is-better-for-js-plugin.167939/