MV Guard Command Error (LeTBS_Commands.js) - SOLVED!

Hi, I use LeCode's Tactical Battle System (LeTBS) and one of the mandatory plugin extensions is LeTBS_Commands.js. It governs the command window where the actor's actions are selected (attack, move, skills, items, etc...). I have mine set up so that equipping a Weapon will add the "Attack" command to the actor. The notetag looks like this: (76 = icon Id)
JavaScript:
<letbs_commands>
attack 76
</letbs_commands>
Similarly, I'd also like for Shields to grant the "Guard" command. However, I get an error when I try the following:
JavaScript:
<letbs_commands>
guard 81
</letbs_commands>
...which gives me this error:
1636194279449.png


This doesn't make sense to me because I've looked at the code and it ought to work! Look, this is the function that creates the list of commands:
JavaScript:
Window_TBSCommand.prototype.makeCommandList = function () {
    if (this._battler) {
        var str = this.getCommandsString();
        var array = str.split(",").map(function (str) {
            return str.trim();
        }).filter(function(str){
            return str;
        });
        this.makeIcons(array);
        array = array.map(function (str) {
            return str.replace(/\s+\d+/ig, "");
        });
        array.forEach(function (com) {
            if (com.match(/skill\[(\d+)\]/i))
                this.addCommand_skill(Number(RegExp.$1));
            else if (com.match(/item\[(\d+)\]/i))
                this.addCommand_item(Number(RegExp.$1));
            else if (com.match(/event\[(\d+)\]/i))
                this.addCommand_event(Number(RegExp.$1));
            else if (com)
            console.log(com);
                eval("this.addCommand_" + com + "();");
        }.bind(this));
    }
};
And here are the functions for attack and guard respectively:
JavaScript:
Window_TBSCommand.prototype.addCommand_attack = function () {
    this.addCommand(TextManager.attack, 'attack', this._entity.canAttackCommand());
};

Window_TBSCommand.prototype.addCommand_guard = function () {
    this.addCommand(TextManager.guard, 'guard', this._entity.canGuardCommand());
};
There are similar functions for all the other commands like "Skills, Items, Move, Pass, Scan, etc..." but I've omitted them here for the sake of brevity. Anyway, I did a console.log(com); to ensure it was outputting "guard" for the eval, which it was. So what the heck is the issue??

Edit: Btw, line 261 (as shown in error msg) is this: eval("this.addCommand_" + com + "();");
So it should theoretically return eval(this.addCommand_guard(););

Edit2: Ok, I realized the problem... Bascially, the "com" is returning the string "attack guard". As in, two words in a single string instead of two separate strings. Notice how "move" is its own thing, whereas "attack guard" is stuck together:
1636195595226.png

How can I split the string up into separate parts and have it do the eval for each part? Regex I imagine?

Edit3: SOLVED! Solution:
JavaScript:
Window_TBSCommand.prototype.makeCommandList = function () {
    if (this._battler) {
        var str = this.getCommandsString();
        var array = str.split(",").map(function (str) {
            return str.trim();
        }).filter(function(str){
            return str;
        });
        this.makeIcons(array);
        array = array.map(function (str) {
            return str.replace(/\s+\d+/ig, "");
        });
        array.forEach(function (com) {
            console.log(com);
            if (com.match(/skill\[(\d+)\]/i)) {
                this.addCommand_skill(Number(RegExp.$1));
            } else if (com.match(/item\[(\d+)\]/i)) {
                this.addCommand_item(Number(RegExp.$1));
            } else if (com.match(/event\[(\d+)\]/i)) {
                this.addCommand_event(Number(RegExp.$1));
            } else if (com.includes(" ")) {
                var coms = com.split(' ');
                console.log(coms);
                for (var i = 0; i < coms.length; i++) {
                    eval("this.addCommand_" + coms[i] + "();");
                }
            } else if (com) {
                eval("this.addCommand_" + com + "();");
            }
        }.bind(this));
    }
};
I also had to edit the following function to get the it to actually carry out the Guard command:
JavaScript:
Window_TBSCommand.prototype.addCommand_guard = function () {
    this.addCommand(TextManager.guard, "skill[" + this._battler.guardSkillId() + "]", this._entity.canGuardCommand());
};

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/guard-command-error-letbs_commands-js-solved.141891/