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

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
493
Reaction score
216
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,712
Reaction score
1,162
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
493
Reaction score
216
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

I didn't think I'd spend the evening jamming out to the battle theme of a Hole Punch.
Welcome back to the dark era, where everything is in dark mode!
.
.
.
I'm not complaining! :o
Currently without internet due to storm damage and most of our state is devastated. No idea how long I'll be unable to log onto here, but I'll answer questions as soon as I can.
This is supposed to be pso2 photon blast inspired animation
I'm sure this question's been asked before, but I can't find an answer: is there any way to run the Steam version of RPGMaker *without* being logged into Steam? It's a frustrating extra step sometimes.

Forum statistics

Threads
100,716
Messages
978,720
Members
132,336
Latest member
shorp_
Top