MV How to check if an enemy exists in battle?

With the SRD HUD Maker plugin, I added HP, MP and TP gauges for the three potential enemies that can show up in battles in my game. They work fine, so long as three enemies exist in the troop. If less than three enemies are available, the game lags to a crawl, it seems like it is constantly trying to locate the enemies so it can get their HP/MP/TP values to generate the gauges?

So, I feel like I need to make use of the plugin's "condition" field to make so the game only tries to generate the gauges if the enemies exist in battle, otherwise skip it. Can anyone help me with this problem? I looked around in the console, but I could not find a statement that does what I want.

I think I figured it out, or at least it is working the way I want it to work, for now.

JavaScript:
$gameTroop.members()[1]

Tada! Put this in the conditions field, replacing the [1] with the number respective to the troop member.
Remember, it should start with 0 for the first enemy.
if it changes to 2 enemies, you may need to flag it.

if ($gameTroop.members()[0]) code here

same for [1] and [2] for 3 troop members.

I don't know if troopMembers shift upon killing them or not,
which should be kept the same till a new battle.

there may be a cleaner approach for it though.
I think I figured it out, or at least it is working the way I want it to work, for now.

JavaScript:
$gameTroop.members()[1]

Tada! Put this in the conditions field, replacing the [1] with the number respective to the troop member.
No… that's not going to work. It will continue to show enemies that have died, and it will show enemies that are set to appear mid-battle. It might be fine if you want to show dead enemies and never use mid-battle appearances, though.

Before actually giving an alternative, I think I should really know the answer to that question. Should dead enemies still be shown?

EDIT: Actually, I'll just give both answers. If you want to include dead enemies, use this as the condition:

JavaScript:
$gameTroop.members()[1] && $gameTroop.members()[1].isAppeared()

If you only want living enemies, use this:

JavaScript:
$gameTroop.members()[1] && $gameTroop.members()[1].isAlive()

Remember the first one is 0, not 1.

I don't know if troopMembers shift upon killing them or not,
which should be kept the same till a new battle.
They do not. The dead enemy remains in its position; it just has the death state applied. It's entirely possible to remove that state and revive it.
No… that's not going to work. It will continue to show enemies that have died, and it will show enemies that are set to appear mid-battle. It might be fine if you want to show dead enemies and never use mid-battle appearances, though.

Before actually giving an alternative, I think I should really know the answer to that question. Should dead enemies still be shown?

EDIT: Actually, I'll just give both answers. If you want to include dead enemies, use this as the condition:

JavaScript:
$gameTroop.members()[1] && $gameTroop.members()[1].isAppeared()

If you only want living enemies, use this:

JavaScript:
$gameTroop.members()[1] && $gameTroop.members()[1].isAlive()

Remember the first one is 0, not 1.


They do not. The dead enemy remains in its position; it just has the death state applied. It's entirely possible to remove that state and revive it.
It is totally fine for the gauges of dead enemies to be shown, I just wanted them to not show up/for the game not to enter single digit territory framerate-wise when there are only one or two enemies in battle. Thanks for the help, though! I applied your first suggestion to the game.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-check-if-an-enemy-exists-in-battle.180606/