Sorry, I thought it was an error made out of my lack of JS knowledge.
I'm editing
Pretty Sleek Gauges plugin:
https://forums.rpgmakerweb.com/index.php?threads/pretty-sleek-gauges.90506/
My goals is to make width of enemy boss bar wider if the enemy has a trait of "Collapse Effect: Boss", which is id 63.
You can get entire code from the link if needed, here's my edited stuff:
JavaScript:
Window_EnemyHPBars.prototype.update = function() {
Window_Base.prototype.update.call(this);
enemies = $gameTroop.members();
this.contents.clearRect(0, 0, Graphics.boxWidth, Graphics.boxHeight);
for (var i = 0; i < enemies.length; i++) {
if (this._enemySprites[i] === undefined) continue;
if (!this._enemySprites[i].height || !this._enemySprites[i].width) continue;
var width = EHPbarWidth, x, y;
eId = enemies[i]._enemyId;
var isBoss = false;
test = $dataEnemies[eId].traits[3];
//for (var j = 0; j < 4; j++){
// if ($dataEnemies[eId].traits[j].code == 63) {
// var isBoss = true;
// break
// }
//}
if (isBoss == true) {
width = 360, x, y;
}
/*
tempId = 16
if (enemy(tempId).traits.code == 63) {
console.out('boss');
} else {
console.out("bossn't");
}
*/
x = enemies[i].screenX() - (width + this.textPadding())/2 + EHPXOffset + (parseInt(enemies[i].enemy().meta.HPBarXOffset) || 0);
y = enemies[i].screenY() - this.lineHeight() + EHPYOffset + (parseInt(enemies[i].enemy().meta.HPBarYOffset) || 0);
if (showUpTop) y -= this._enemySprites[i].height * EHPYMultiplier;
this.drawEnemyGauges(enemies[i], x, y, width);
}
}
Sorry it's messy, I'm a beginner and it's still work in progress~
EDIT: whoops, forgot to add
The error indicates that the enemy does not have a traits[3] element. Remember they start at 0, not 1, and you can't guarantee how many they have unless you have gone through and ensured that every enemy has at least 4 traits.
It's a 4th trait. That's why it works well in the console, I guess.
@Andar I believe your point might be the case. I don't have any idea how to fix that yet, I'll think about it but any help is welcome!
EDIT2: I just tried doing
console.log(test); in the code. Andar was right, the traits aren't defined at start. I guess I need to figure out how to force them to load now... OR I'll check another plugins' code for hints.