Why doesn't this work? (changing paint opacity)

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
468
Reaction score
204
First Language
English
Primarily Uses
RMMV
I have this code which should draw some enemies grayed out in the target selection menu, but for some reason it doesn't do anything, even though the paint opacity is clearly still 160 when it reaches the draw text call. Any idea what I'm missing here?

JavaScript:
Window_BattleEnemy.prototype.isCurrentItemEnabled = function() {
    var canTarget = true, enemy = this.enemy();
    if(enemy) canTarget = enemy.tgr > 0;
    return canTarget && Window_Selectable.prototype.isCurrentItemEnabled.call(this);
};

const old_drawEnemyItem = Window_BattleEnemy.prototype.drawItem;
Window_BattleEnemy.prototype.drawItem = function(index) {
    this.changePaintOpacity(this.isCurrentItemEnabled());
    old_drawEnemyItem.call(this, index);
    this.changePaintOpacity();
};
(In case you're wondering, the use-case for this is an "invisible" state.)
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
1,703
Reaction score
1,148
First Language
EN
Primarily Uses
RMMV
It's because your drawItem alias only references the enemy that's currently selected at the time of drawing; you'll want to reference the appropriate index instead. Also, it may be worth noting that the window's items are only redrawn when the window is refreshed, e.g. when it initialises and when the list is scrolled. :kaoswt:

In short, try replacing this line:
JavaScript:
    this.changePaintOpacity(this.isCurrentItemEnabled());
...with this:
JavaScript:
    this.changePaintOpacity(this._enemies[index].tgr > 0);
:kaopride:

[Edit: me English better now. :kaoslp:]
 
Last edited:

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
468
Reaction score
204
First Language
English
Primarily Uses
RMMV
Aha, that makes sense. How did I miss that... anyway it works now. Thanks.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

just a few more hours until the toughest, most pressure 72 hours of my life, wish me luck guys
Working on some bosses for my game-
His tracks are always so wonderful.
In a narrative Choose Your Own Adventure-style RPG, do you prefer the narrative to be in 2nd person ("you saw", "you thought"), or 3rd person ("he saw", "he thought")?

What's your preference, and why?

Forum statistics

Threads
100,558
Messages
977,220
Members
132,136
Latest member
alfredotrojse
Top