MZ I cannot get this script to work, what's wrong with it?

I'm trying to make the number of commands displayed in the command window during the battle to suit each actor, in this case my main actor Leasha has 8 commands, my second actor named Xeras has 6 and the rest 5, for some reason Reason with the code I made, it only takes the last line and all are put with 5 commands, what's wrong with this code, why doesn't it allow my actor 1 and 2 to change their commands as I put it in the code?



JavaScript:
    const alias = Scene_Battle.prototype.actorCommandWindowRect;

    Scene_Battle.prototype.actorCommandWindowRect = function() {

       const rect = alias.apply(this, arguments);

       if (BattleManager.actor() == $gameActors.actor(1).name()) {

        rect.height = this.calcWindowHeight(8, true);

       } else if (BattleManager.actor() == $gameActors.actor(2).name()) {

        rect.height = this.calcWindowHeight(6, true);

       } else {

        rect.height = this.calcWindowHeight(5, true);

       }

       return rect;
You have several errors in that code.

First, for some reason you're comparing an actor - the return value of BattleManager.actor() - to a string - the return value of $gameActors.actor(X).name()

So that will never give a true result, as an actor will never be equal to a string.

Secondly, even if you wanted to look at the name (which you don't), name is not a getter function. It's just a member variable. So the correct syntax would be $gameActors.actor(X).name

But you just want to ask BattleManager.actor() == $gameActors.actor(X)
Those both return an actor, and comparing an actor to an actor is a valid comparison.

Just to offer the input...are you sure you want to do this? From a UI perspective, I would consider it to look very janky if that window kept popping up larger into the battlefield then back down then up.

Having it at a uniform height with the battle status menu with the scrolling commands is better by a UX design standard.
As Turan said, you're comparing an object to a string. That can never be true.

Where did you get the idea that this kind of code was what you'd need to accomplish what you're trying to do?
you are also missing a closing backet "}" on the end which is still open.
so it should throw an error of that as well.

if you use VScode, you can reconize those.
I need to warn you @LeashaX that you do need to be careful about how you insert your custom battle commands in that menu. If you still depend on some index based checks to find out what function should be called to set the actor's next skill or item or the like, your battle system is already broken. I guess you'll need to use "strings" as value code to be checked by the conditions determining your actor's next action.

Original thread: https://forums.rpgmakerweb.com/threads/i-cannot-get-this-script-to-work-whats-wrong-with-it.154397/