Important battle system build-in code

Hi! Please help me out. I am creating my very own Conditional Turn Battle battle system for my own RMMV game, in JS (Javascript). I have gotten somewhere already. I just want to know certain build-in code and what they mean from the default RMMV project files.

Let's see, I need several things. I need to know battle system things like different parts of the battle, the code for making it a certain actor's or enemy's turn, how to make your actor input when you need it and other such things. My CTB needs to start a battler's turn based on their agility and speed of their last skill if there was one. I can do this on my own (I have already made progress about this) but I need to know what build-in code I need to alter/override and what each line/command of it means.
I don't know what you know, but try this!
It's better if you go through the code yourself then ask questions about parts of the code instead of asking "how does all of this work"
For the default battle system codebase, you may want to read this.
Specifically:

1. "making it a certain actor's or enemy's turn" is done by Game_Battler.prototype.makeActions, and their Game_Actor, Game_Enemy counterparts:
Spoiler
JavaScript:
Game_Battler.prototype.makeActions = function() {
    this.clearActions();
    if (this.canMove()) {
        var actionTimes = this.makeActionTimes();
        this._actions = [];
        for (var i = 0; i < actionTimes; i++) {
            this._actions.push(new Game_Action(this));
        }
    }
};
JavaScript:
Game_Actor.prototype.makeActions = function() {
    Game_Battler.prototype.makeActions.call(this);
    if (this.numActions() > 0) {
        this.setActionState('undecided');
    } else {
        this.setActionState('waiting');
    }
    if (this.isAutoBattle()) {
        this.makeAutoBattleActions();
    } else if (this.isConfused()) {
        this.makeConfusionActions();
    }
};
JavaScript:
Game_Enemy.prototype.makeActions = function() {
    Game_Battler.prototype.makeActions.call(this);
    if (this.numActions() > 0) {
        var actionList = this.enemy().actions.filter(function(a) {
            return this.isActionValid(a);
        }, this);
        if (actionList.length > 0) {
            this.selectAllActions(actionList);
        }
    }
    this.setActionState('waiting');
};
In the default battle system, makeActions is called upon the start of the actor input phase for all battlers(or action execution phase for all enemies if there's no inputable actors).
In a CTB system, it should be called right after the hidden CTB meter of a battler becomes full.

2. "how to make your actor input when you need it" is done by Scene_Battle.prototype.startActorCommandSelection:
Spoiler
JavaScript:
Scene_Battle.prototype.startActorCommandSelection = function() {
    this._statusWindow.select(BattleManager.actor().index());
    this._partyCommandWindow.close();
    this._actorCommandWindow.setup(BattleManager.actor());
};
In the default battle system, startActorCommandSelection is called by either the fight command of the party command window or finishing inputting all actions of the currently inputting actor.
In a CTB system, when an actor becomes inputable, it should notify BattleManager to update its list of inputable actors, then BattleManager should notify Scene_Battle that the list of inputable actors has changed so it might need to setup the actor command window for a newly inputable actor, if no inputable actors' already selected for inputting actions(things can be simplified if you're sure there will only be at most 1 inputable actor at a time).
Setting up such an actor should be done by BattleManager.changeActor:
Spoiler
JavaScript:
BattleManager.changeActor = function(newActorIndex, lastActorActionState) {
    var lastActor = this.actor();
    this._actorIndex = newActorIndex;
    var newActor = this.actor();
    if (lastActor) {
        lastActor.setActionState(lastActorActionState);
    }
    if (newActor) {
        newActor.setActionState('inputting');
    }
};

Combining everything can lead to codes like this:
Spoiler
JavaScript:
BattleManager.addCTBInputableActor = function(actor) {
    if (this._ctbInputableActors.contains(actor)) return;
    this._ctbInputableActors.push(actor);
    this.changeActor(actor.index(), "");
    if (!$gameParty.inBattle()) return;
    SceneManager._scene.startActorCommandSelection();
}
Game_Battler.prototype.updateCTB = function() {
    if (this.ctbMeter >= this.maxCTBMeter) return;
    this.ctbMeter += this.ctbRate();
    if (this.ctbMeter < this.maxCTBMeter) return;
    this.onCTBBecomesFull();
};
Game_Battler.prototype.onCTBBecomesFull = function() {
    this.makeActions();
};
Game_Actor.prototype.onCTBBecomesFull = function() {
    Game_Battler.prototype.onCTBBecomesFull.call(this);
    BattleManager.addCTBInputableActor(this);
};
Alternatively, if you're sure there will only be at most 1 inputable actor at a time:
Spoiler
JavaScript:
Game_Battler.prototype.updateCTB = function() {
    if (this.ctbMeter >= this.maxCTBMeter) return;
    this.ctbMeter += this.ctbRate();
    if (this.ctbMeter < this.maxCTBMeter) return;
    this.onCTBBecomesFull();
};
Game_Battler.prototype.onCTBBecomesFull = function() {
    this.makeActions();
};
Game_Actor.prototype.onCTBBecomesFull = function() {
    Game_Battler.prototype.onCTBBecomesFull.call(this);
    BattleManager.changeActor(this.index(), "");
    if (!$gameParty.inBattle()) return;
    SceneManager._scene.startActorCommandSelection();
};
Of course, this snippet can't be just embedded as-is, as it's just an example to show 1 such possible high level flow regarding "making it a certain actor's or enemy's turn" and "how to make your actor input when you need it, and you'll still have to polish it to make it work in your CTB system plugin 🙂
@DoubleX That was quite a good post there. But I don't really understand those JS scripts. Please help me out again.
@DoubleX That was quite a good post there. But I don't really understand those JS scripts. Please help me out again.
So I assume you've already read Solid understanding to the default RMMV battle flow implementations and its prerequisite - Basic knowledge to the default RMMV battle flow implementations, but still failed to understand a thing relevant to your CTB system plugins.
It'd help posting the parts of your CTB system plugins needing help, but assuming that it's not feasible for some reasons, and it seems to me that there are just too many parts you don't understand for you to list them in your reply, you may want to read Basic knowledge on writing ATB(Active Time Battle) system plugins as well, as you should be able to write a CTB system plugin if you know how to write an ATB counterpart(and it's an easy, simple and small task to convert a well-written ATB system plugin to have CTB behaviors).

For now, here's my following try:
1. "the code for making it a certain actor's or enemy's turn" -
i. In a CTB system, the start of a battler's turn's the moment that battler becomes able to input actions
ii. Every battler will create their new action slots(the private instance variable _actions of each battler) upon becoming able to input actions, and those action slots are made by makeActions
2. "how to make your actor input when you need it"
i. For inputable actors, the actor command window needs to be setup to let players input actions for those actors, and setting up the actor command window's done by startActorCommandSelection(you don't need to worry much about how players input actions as they should be largely the same as the default RMMV battle system)
ii. For enemies and non-inputable actors(auto battle and confusion), all actions are immediately inputted right after those action slots are made(by setting up the skill/item to be executed for each action slot)
So I've tried learning it. I have tried learning from the built-in code and changing it and from the above articles. Maybe I understand it a little bit more now. At least now I have some questions, please answer them:

1) What exactly does makeActions() do? I have disabled it and seems nothing has changed in battle. I thought that it would disable my actors' turns coming up or their skills being used. But it didn't.
2) What exactly calls the startActorCommandSelection()? I don't see it anywhere in the built-in files.
1) What exactly does makeActions() do? I have disabled it and seems nothing has changed in battle. I thought that it would disable my actors' turns coming up or their skills being used. But it didn't.
2) What exactly calls the startActorCommandSelection()? I don't see it anywhere in the built-in files.
1) Make actions allocate action slot for the battle involved, and without action slots, the battler won't be able to execute any action at all.
As you said nothing seems to have changed in battle even after disabling makeActions(), you may want to show how exactly you disabled that.
2) It's called by Scene_Battle.prototype.changeInputWindow 🙂

Original thread: https://forums.rpgmakerweb.com/threads/important-battle-system-build-in-code.124921/