Formation Menu from script/event

Hi all,

I am making some changes to the way the UI works in my game (more a prototype than a game, but never mind) and I was looking for a way to call up the Formation Menu, which as far as I understand cannot be called like the other menus by pushing using the SceneManager a corresponding Scene object. I looked for a solution in this forum and in a couple threads I saw people saying that it was possible to cal the Formation Menu using script commands but I could not find any concrete code example that I could use or at least adapt.

Right now I have implemented formation changes by using a combination of text boxes, input numbers and direct calls to the $gameParty methods, but it looks ugly and not very intuitive.

Does anyone know what kind of functions calls would be necessary to call up the standard Formation Menu programmatically (i.e. from a .js file or within an event)? Thanks in advance for the suggestions!
I don't believe you can, without rewriting some of how the menu itself works.

By default, Formation is a mode of the menu scene. So you can use script calls to get into it:
Code:
SceneManager.push(Scene_Menu);
SceneManager._scene.commandFormation();

but the second line won't function until the scene itself is loaded, which is not instantaneous. So simply entering those as two lines of code like that won't work. You have to push the scene change, then once it's been constructed you can do commandFormation() instead of scrolling to and selecting the formation command.

Or you rewrite the menu so that's the default mode and change the default command bindings.

Or you make a second scene that's a copy of Scene_Menu but has that different default mode and command bindings, and push to that scene.

Or you event it.

Or you use something like Yanfly's Party Manager which gives you an interface for this outside of the formation mode of the menu.
If none of the above suggestions of @ATT_Turan works for you, you may be able to try this:

JavaScript:
SceneManager.push(Scene_Menu)
window.myInterval = setInterval(function () {
    if(SceneManager._scene.constructor.name === "Scene_Menu" && SceneManager._scene.isReady()){
        SceneManager._scene._commandWindow.selectSymbol("formation")
        SceneManager._scene._commandWindow.callOkHandler()
        clearInterval(window.myInterval)
    }else{
        
    }
}, 1000);

This will call the Scene Menu and after that make the game keep checking every second if you are on the Scene Menu. When you get there, and the scene is ready, it will automatically select the formation symbol and confirm that selection.

You can change the 1000, to any number you want. That value is in MS, so 1000 MS = 1 Second.
I don't believe you can, without rewriting some of how the menu itself works.

By default, Formation is a mode of the menu scene. So you can use script calls to get into it:
Code:
SceneManager.push(Scene_Menu);
SceneManager._scene.commandFormation();

but the second line won't function until the scene itself is loaded, which is not instantaneous. So simply entering those as two lines of code like that won't work. You have to push the scene change, then once it's been constructed you can do commandFormation() instead of scrolling to and selecting the formation command.

Or you rewrite the menu so that's the default mode and change the default command bindings.

Or you make a second scene that's a copy of Scene_Menu but has that different default mode and command bindings, and push to that scene.

Or you event it.

Or you use something like Yanfly's Party Manager which gives you an interface for this outside of the formation mode of the menu.
Thanks for the quick reply! Could you perhaps elaborate on the second ("make a second scene") and third ("event it") option you mention?

I would interpret the second option as creating a Scene object that is a subclass of Scene_Menu and overriding whatever method is called when the scene is pushed with "SceneManager._scene.commandFormation()" but I am not sure how to go about it in JavaScript (I also apologise if my terminology sounds weird, I am new to RPG Maker and when it comes to scripting I am essentially winging it based on my past experience with Java).

As to "eventing it", I am drawing a blank - I have not seen any event command that I can use to call up menus, just to enable/disable access to them.

Once again thanks in advance for any help I can get!
If none of the above suggestions of @ATT_Turan works for you, you may be able to try this:

JavaScript:
SceneManager.push(Scene_Menu)
window.myInterval = setInterval(function () {
    if(SceneManager._scene.constructor.name === "Scene_Menu" && SceneManager._scene.isReady()){
        SceneManager._scene._commandWindow.selectSymbol("formation")
        SceneManager._scene._commandWindow.callOkHandler()
        clearInterval(window.myInterval)
    }else{
      
    }
}, 1000);

This will call the Scene Menu and after that make the game keep checking every second if you are on the Scene Menu. When you get there, and the scene is ready, it will automatically select the formation symbol and confirm that selection.

You can change the 1000, to any number you want. That value is in MS, so 1000 MS = 1 Second.
Thanks for the suggestion, I have tried it and it sort of works, but in this way I still get the whole main menu open, it just automates the clicking of the "Formation" option. What I was looking for was a way to have just the sub-window in which you do the formation change open so that I can change the party formation, and then close it when I press the cancel button.

PS: sorry, I just noticed I could have quoted both replies in a single post... newbie mistake
I would interpret the second option as creating a Scene object that is a subclass of Scene_Menu and overriding whatever method is called when the scene is pushed with "SceneManager._scene.commandFormation()"
Basically; a new scene that inherits from Scene_Menu but has the values that commandFormation() changes set as the default instead.

As to "eventing it", I am drawing a blank - I have not seen any event command that I can use to call up menus, just to enable/disable access to them.

Thanks for the suggestion, I have tried it and it sort of works, but in this way I still get the whole main menu open, it just automates the clicking of the "Formation" option.
That's all you can do.

What I was looking for was a way to have just the sub-window in which you do the formation change open so that I can change the party formation, and then close it when I press the cancel button.
I'm not sure what you mean - can you provide a screenshot? There is no sub-window - all that the Formation command does is move the cursor from the left side of the screen, where you have the menu commands, over to the right side of the screen, where you have the actors' faces.

All of the menu windows are open all of the time in this process, nothing visually changes.

Default menu screen:
1718846608629.png


In the Formation command:
1718846631846.png


This makes it sound even more like you want a custom scene. You could check out the Graphical Design Mode plugin, I'm not sure if that helps you make new scenes.

Otherwise, you can post a request in Plugin Support; and if that doesn't get any traction for friendly free, you can post a paid commission once you get to 30 posts and unlock that section.
Basically; a new scene that inherits from Scene_Menu but has the values that commandFormation() changes set as the default instead.




That's all you can do.


I'm not sure what you mean - can you provide a screenshot? There is no sub-window - all that the Formation command does is move the cursor from the left side of the screen, where you have the menu commands, over to the right side of the screen, where you have the actors' faces.

All of the menu windows are open all of the time in this process, nothing visually changes.

Default menu screen:
View attachment 308946

In the Formation command:
View attachment 308947

This makes it sound even more like you want a custom scene. You could check out the Graphical Design Mode plugin, I'm not sure if that helps you make new scenes.

Otherwise, you can post a request in Plugin Support; and if that doesn't get any traction for friendly free, you can post a paid commission once you get to 30 posts and unlock that section.
Thanks for the clarification. I guess I do want a custom Scene, one that replicates the functionality of the main menu as far as the party composition is concerned. In other words, I'd like to have a Scene_Formation that I can push with the SceneManager to make the list of actors' faces alone (i.e. with no list "Item, Skill, etc." alongside it) appear and and allow the player to change the order of the actors if they so wish. I thought I could copy or adapt existing code since the functionality exists already, but I could not find any resource explaining clearly how the internals of the Scenes work.

I will give a little background: I felt that the basic interaction mode in RPG Maker was a bit limited, so I programmed a couple of new actions, such as "Examine" or "Use Item" that can be used within the game map (basically, they allow the implemetation of puzzles like the ones found in graphical adventures). I bound these additional actions to keyboard shortcuts, but I wanted them in the game menu as well. As I said, it's not clear to me how Scenes work, so I "evented" a new main menu using exactly the tutorial in link you are mentioning (I did a bit more actually, my custom menu has also mouse support, the menu in the tutorial is exclusively keyboard-driven). In the end, I was able to implement my new commands and to replicate all the commands in the standard main menu in my custom-made menu except for "Formation", because it does not have its dedicated Scene object nor an event command.

Right now I have implemented the "Formation" functionality, but it's quite ugly to see and it would be nice to have the same look and feel of the others. Rather than writing something from scratch I thought to ask around to see if someone had an already-made solution or could at least point me in the right direction to program one myself. From Eliaquim's reply and yours I suspect I have no such luck, but I hope at least now it's clear what I'm after!
I could not find any resource explaining clearly how the internals of the Scenes work.
Not really, they require some proficiency in JavaScript to be able to read and follow through how everything works.

What you're asking isn't terribly difficult, but it's a bit tedious because someone will have to make sure they're setting all of the properties appropriately and do testing on it. It's not something someone will whip up in two minutes and drop into this thread for you.

I thought to ask around to see if someone had an already-made solution
Did you look at the Party Manager plugin I mentioned before? It has a dedicated interface without any superfluous commands that you can call at any time via plugin command.

Aside from that, you can work on the rest of the game and have time to either learn JavaScript if you like, or save up some cash as an incentive.
Not really, they require some proficiency in JavaScript to be able to read and follow through how everything works.

What you're asking isn't terribly difficult, but it's a bit tedious because someone will have to make sure they're setting all of the properties appropriately and do testing on it. It's not something someone will whip up in two minutes and drop into this thread for you.


Did you look at the Party Manager plugin I mentioned before? It has a dedicated interface without any superfluous commands that you can call at any time via plugin command.

Aside from that, you can work on the rest of the game and have time to either learn JavaScript if you like, or save up some cash as an incentive.
Well, my question was prompted more by a desire of not reinventing the wheel combined with my innate laziness...

I wrote the custom scene, it was boring but quite easy once I made peace with the idea of doing it myself (not really two minutes, but not more than fifteen). The journey is perhaps as important as the destination, so here's what I did, following the hints I got from you:
- I went to the code for Scene_Menu in rpg_scenes.js (in my version of RPG Maker, it's line 959);
- Copied everything about the scene in the custom plugin I use for my game;
- Renamed every instance of Scene_Menu in the code in Scene_Formation;
- Edited the create method of the class leaving only the line this.createStatusWindow();
- Edited the start method by appending the lines that can be found in the method commandFormation and further edited the last two lines;
- Edited the else branch of the OnFormationCancel method so as to contain only the instruction this.Popscene() in order to quit the scene cleanly;
-
Deleted everything having nothing to do with the above.

For anybdody else in who might be interested in the same function, I attach the final code I came up with below.

Disclaimer: the code is provided "as is", no warranties. I did test it in my game and with the console and as far as I can tell it works as it should. Maybe there are more elegant ways of achieving the same result and I cannot exclude that some spurious code is still there. If anybody finds anything wrong or make improvements that they want to share that'd be great.

It's a quick edit of stock code so it should be compatible with most other plugins/customisations, for the same reason I don't dream of asking any acknowledgement or pose any restriction as to how anyone might want to use it.

JavaScript:
// Custom Scene Formation. It replicates the functionality of the command
// "Formation" on the game screen. Invoke with script command:
// SceneManager(Scene_Formation);

function Scene_Formation() {
    this.initialize.apply(this, arguments);
};

Scene_Formation.prototype = Object.create(Scene_MenuBase.prototype);
Scene_Formation.prototype.constructor = Scene_Formation;

Scene_Formation.prototype.initialize = function() {
    Scene_MenuBase.prototype.initialize.call(this);
};

Scene_Formation.prototype.create = function() {
    Scene_MenuBase.prototype.create.call(this);
    this.createStatusWindow();
};

Scene_Formation.prototype.start = function() {
    Scene_MenuBase.prototype.start.call(this);
    this._statusWindow.refresh();
    this._statusWindow.setFormationMode(true);
    this._statusWindow.selectLast();
    this._statusWindow.activate();
    this._statusWindow.setHandler('ok',     this.onFormationOk.bind(this));
    this._statusWindow.setHandler('cancel', this.onFormationCancel.bind(this));
};


Scene_Formation.prototype.createStatusWindow = function() {
    this._statusWindow = new Window_MenuStatus(0, 0);
    this._statusWindow.reserveFaceImages();
    this.addWindow(this._statusWindow);
};


Scene_Formation.prototype.onFormationOk = function() {
    var index = this._statusWindow.index();
    var actor = $gameParty.members()[index];
    var pendingIndex = this._statusWindow.pendingIndex();
    if (pendingIndex >= 0) {
        $gameParty.swapOrder(index, pendingIndex);
        this._statusWindow.setPendingIndex(-1);
        this._statusWindow.redrawItem(index);
    } else {
        this._statusWindow.setPendingIndex(index);
    }
    this._statusWindow.activate();
};

Scene_Formation.prototype.onFormationCancel = function() {
    if (this._statusWindow.pendingIndex() >= 0) {
        this._statusWindow.setPendingIndex(-1);
        this._statusWindow.activate();
    } else {
        this.popScene();
    }
};

Original thread: https://forums.rpgmakerweb.com/threads/formation-menu-from-script-event.169631/