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)
Similarly, I'd also like for Shields to grant the "Guard" command. However, I get an error when I try the following:
...which gives me this error:
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:
And here are the functions for attack and guard respectively:
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
Edit: Btw, line 261 (as shown in error msg) is this:
So it should theoretically return
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:
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:
I also had to edit the following function to get the it to actually carry out the Guard command:
JavaScript:
<letbs_commands>
attack 76
</letbs_commands>
JavaScript:
<letbs_commands>
guard 81
</letbs_commands>
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));
}
};
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());
};
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:
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));
}
};
JavaScript:
Window_TBSCommand.prototype.addCommand_guard = function () {
this.addCommand(TextManager.guard, "skill[" + this._battler.guardSkillId() + "]", this._entity.canGuardCommand());
};