Understanding Battle Commands

I'm trying to change the control scheme of the Battle Scene, looking at Window_Actorcommand I'm not sure where to start, how exactly are commands pushed? My goal is to input commands in an alternate way rather than the default selection menus, like a key/touch input.

For reference this is where I'm looking:
Code:
//-----------------------------------------------------------------------------
// Window_ActorCommand
//
// The window for selecting an actor's action on the battle screen.

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

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

Window_ActorCommand.prototype.initialize = function() {
    var y = Graphics.boxHeight - this.windowHeight();
    Window_Command.prototype.initialize.call(this, 0, y);
    this.openness = 0;
    this.deactivate();
    this._actor = null;
};

Window_ActorCommand.prototype.windowWidth = function() {
    return 192;
};

Window_ActorCommand.prototype.numVisibleRows = function() {
    return 4;
};

//Window_ActorCommand.prototype.makeCommandList = function() {
//    if (this._actor) {
//        this.addAttackCommand();
//        this.addSkillCommands();
//        this.addGuardCommand();
//        this.addItemCommand();
//    }
//};

Window_ActorCommand.prototype.addAttackCommand = function() {
    this.addCommand(TextManager.attack, 'attack', this._actor.canAttack());
};

Window_ActorCommand.prototype.addSkillCommands = function() {
    var skillTypes = this._actor.addedSkillTypes();
    skillTypes.sort(function(a, b) {
        return a - b;
    });
    skillTypes.forEach(function(stypeId) {
        var name = $dataSystem.skillTypes[stypeId];
        this.addCommand(name, 'skill', true, stypeId);
    }, this);
};

Window_ActorCommand.prototype.addGuardCommand = function() {
    this.addCommand(TextManager.guard, 'guard', this._actor.canGuard());
};

Window_ActorCommand.prototype.addItemCommand = function() {
    this.addCommand(TextManager.item, 'item');
};

Window_ActorCommand.prototype.setup = function(actor) {
    this._actor = actor;
    this.clearCommandList();
    this.makeCommandList();
    this.refresh();
    this.selectLast();
    this.activate();
    this.open();
};

Window_ActorCommand.prototype.processOk = function() {
    if (this._actor) {
        if (ConfigManager.commandRemember) {
            this._actor.setLastCommandSymbol(this.currentSymbol());
        } else {
            this._actor.setLastCommandSymbol('');
        }
    }
    Window_Command.prototype.processOk.call(this);
};

Window_ActorCommand.prototype.selectLast = function() {
    this.select(0);
    if (this._actor && ConfigManager.commandRemember) {
        var symbol = this._actor.lastCommandSymbol();
        this.selectSymbol(symbol);
        if (symbol === 'skill') {
            var skill = this._actor.lastBattleSkill();
            if (skill) {
                this.selectExt(skill.stypeId);
            }
        }
    }
};
Follow how the functions like addAttackCommand does it, which will point you to the addCommand function of Window_Command (the "parent" of Window_ActorCommand) or Window_Selectable (the "parent" of Window_Command)

Take note that this is simply to add the commands to the list.

If you want to input using alternative keystrokes (lile to make shortcuts for some commands), you should check Window_Selectable and Window_Command for the process function which I'm not sure what the name is in MV.

You will then "overwrite" that function in your Window_ActorCommand object in order for the changes that you will make to only affect that specific command window instead of all command windows.

You would probably also need to see BattleManager or Scene_Battle to see which functions these commands actually call when selected
Commands are added inside makeCommandList method of the window. Their handler functions are by default bound to them inside their respective scenes. Nevertheless, if you want to input commands ONLY through key/touch input, it might be better to drop the commandWindow and go for Window_Base (or even drop that completely and go directly for the Scene_Battle!) prototype instead, you can just set listener functions inside the update function:
Code:
let alias = Scene_Battle.prototype.update;
Scene_Battle.prototype.update = function () {
alias.call(this);
if (this._phaseChoosingCommand){
this._phaseChoosingCommand = false;
if (Input.isTriggered("ok")) this.commandAtk();
else if (Input.isTriggered("cancel")) this.commandEscape();
else if (Input.isTriggered("control")) this.commandCastArmageddon();
}
}
That was very silly of me to skip scene_battle and go straight to the window... I've run into something else however, when this.commandAttack is run I select the enemy and then nothing happens, I can select the enemy over and over again and the attack won't execute. I'm guessing its because the actor isn't defined or something? I tried with this.commandGuard and got a softlock.

Heres what im working with, I wanted to create a clickable one first:

Code:
Scene_Battle.prototype.createBattleMenu = function() {
        this._attackbutton = new Sprite_Button();
        this._attackbutton.bitmap = ImageManager.loadPicture('Attack');
        this.addChild(this._attackbutton);
        this._attackbutton.x = Graphics.width / 2
        this._attackbutton.setClickHandler(this.AttackButton.bind(this));

Scene_Battle.prototype.AttackButton = function() {
    this.commandAttack();
};
You can't expect to use functions that are not redefined properly. So what you can (and I guess should) do is find the definition of Scene_Battle.prototype.commandAttack.
Code:
Scene_Battle.prototype.commandAttack = function() {
    BattleManager.inputtingAction().setAttack();
    this.selectEnemySelection();
};
BattleManager method doesn't have anything to do with the command window, so you skip that.
Check the dwfinition of selectEnemySelection.
Code:
Scene_Battle.prototype.selectEnemySelection = function() {
    this._enemyWindow.refresh();
    this._enemyWindow.show();
    this._enemyWindow.select(0);
    this._enemyWindow.activate();
};
We can see that this function just activates the enemy window. So we need to check for enemy window handlers. Let's see onEnemyOk.
Code:
Scene_Battle.prototype.onEnemyOk = function() {
    var action = BattleManager.inputtingAction();
    action.setTarget(this._enemyWindow.enemyIndex());
    this._enemyWindow.hide();
    this._skillWindow.hide();
    this._itemWindow.hide();
    this.selectNextCommand();
};
From this it looks like selectNextCommand is important, because the rest just hides windows (If you use 3rd party plugins that influence this, you may want to be searching through these instead).
Code:
Scene_Battle.prototype.selectNextCommand = function() {
    BattleManager.selectNextCommand();
    this.changeInputWindow();
};
Here BattleManager may be important. What is definitely important rhough is changeInputWindow, because you're not using an inputWindow anymore.
Code:
Scene_Battle.prototype.changeInputWindow = function() {
    if (BattleManager.isInputting()) {
        if (BattleManager.actor()) {
            this.startActorCommandSelection();
        } else {
            this.startPartyCommandSelection();
        }
    } else {
        this.endCommandSelection();
    }
};
None of this code is valid for you and as such this is a step that needs to be changed in order to work (in other words either selectNextCommand or the step before that needs to be redefined). I'm not going to provide any details, since I have absolutely no idea how concretely is your system supposed to work. But I have at least shown you how to trace down the problem.
I've made some progress but I'm not sure how to prevent the spamming of the button.
The way I have it atm, the player is able to input at any time allowing infinite moves within their turn, and if the button is pressed during the enemy turn it throws an error.

Is there something that already exists that I could add as a condition for the player to be able to input commands? I'm guessing I have to make my own since I'm pretty much ditching the selection windows.
That's a basic if else. If he is allowed to click, then the click will trigger command. If not, nothing happens. MV uses phases by default, "inputting", "waiting"...

Original thread: https://forums.rpgmakerweb.com/threads/understanding-battle-commands.106060/