MZ Problems checking for enemy index

I want to check for enemy index, but it doesn't work
if (user == $gameTroop.members()[0])
assuming youre using that in someplace where user is a valid reference, it should work. where exactly are you running that and what are you trying to accomplish?

also your game pretty much only uses unique enemies in each troop right? another option for you would be to check by enemy id
I use it with VS notetags. Here's the relevant part. It works with actor.id, but I can't do same for enemies, because it would be extremely tedious, so I need to get index to work.

if (user == $gameTroop.members()[1]) {
$gameVariables.setValue(282, $gameTroop.members()[1].name());
$gameVariables.setValue(285, $gameTroop.members()[1]._brPotency * $gameTroop.members()[1]._brStack);
$gameTemp.reserveCommonEvent(522);
}
I use it with VS notetags
which one are you using

Here's the relevant part
what about it "isnt working"? what you wrote is set up correctly. as long as user is a defined variable in whatever tag youre using, your condition will pass if the user is the second enemy.

is the condition failing entirely? is variable 285 not being set? something else?


also once youre in your condition, user can only be that enemy. you can just use user after that point instead of $gameTroop.members()[1]
User doesn't get defined, that's a problem. Oh, and also it's featured in a notetag for a state "Post-Turn End" one.
Oh, and also it's featured in a notetag for a state "Post-Turn End" one.
the tag on the website is JS Post-End Turn, not JS Post-Turn End.
if that doesnt work, id suggest showing the contents of the entire notebox here
The tag itself works, here's the full code.

<Reapply Rules: Add>
---
<JS Post-End Turn>
//Check if can burn
if ($gameVariables.value(155) >= 4 && !user.isStateAffected(47)) {
//Proc burn damage
user.gainHp(Math.ceil(user._brPotency * user._brStack * -1));
user._brStack += 1;
user.addState(47)
//Get user name for combat log
if (user.actorId() == 1) {
$gameVariables.setValue(277, $gameParty.members()[0].name());
$gameVariables.setValue(279, $gameParty.members()[0]._brPotency * $gameParty.members()[0]._brStack);
$gameTemp.reserveCommonEvent(519);
}
if (user.actorId() == 2) {
$gameVariables.setValue(278, $gameParty.members()[1].name());
$gameVariables.setValue(280, $gameParty.members()[1]._brPotency * $gameParty.members()[1]._brStack);
$gameTemp.reserveCommonEvent(520);
}
if (user == $gameTroop.members()[0]) {
$gameVariables.setValue(281, $gameTroop.members()[0].name());
$gameVariables.setValue(284, $gameTroop.members()[0]._brPotency * $gameTroop.members()[0]._brStack);
$gameTemp.reserveCommonEvent(521);
}
if (user == $gameTroop.members()[1]) {
$gameVariables.setValue(282, $gameTroop.members()[1].name());
$gameVariables.setValue(285, $gameTroop.members()[1]._brPotency * $gameTroop.members()[1]._brStack);
$gameTemp.reserveCommonEvent(522);
}
if (user == $gameTroop.members()[2]) {
$gameVariables.setValue(283, $gameTroop.members()[2].name());
$gameVariables.setValue(286, $gameTroop.members()[2]._brPotency * $gameTroop.members()[2]._brStack);
$gameTemp.reserveCommonEvent(523);
}
//Get Potency / 3 for further application
$gameVariables.setValue(69, Math.ceil(user._brPotency / 3));
$gameTemp.reserveCommonEvent(16);
}
//Remove 'BurnBlock' after 'Burn' proc
if ($gameVariables.value(155) < 4) {
user.removeState(47);
}
</JS Post-End Turn>
---
<JS On Add State>
//Start burn count if 0
this._brPotency = this._brPotency || 1;
this._brStack = this._brStack || 1;
this.setStateDisplay(55, this._brPotency);
</JS On Add State>
---
<JS On Erase State>
delete this._brPotency;
delete this._brStack;
</JS On Erase State>
---
<JS On Expire State>
delete this._brPotency;
delete this._brStack;
</JS On Expire State>
---
<Help Description>
At end of every 2-3 player turns:
Deals %1 * Stack Amount DMG\n
Reapplies 1/3 of user potency to random battler\n
Will proc this turn?: \V[156]
</Help Description>
you shouldnt use user.actorId() without making sure that user can only be an actor first. if the user isnt an actor, that first IF will produce an error and the rest of your notetag wont be ran.

you can condense all of the middle section to this and it should be fine

Code:
...
//Get user name for combat log
if (user.isActor()) {
    $gameVariables.setValue(276 + user.actorId(), user.name());
    $gameVariables.setValue(278 + user.actorId(), user._brPotency * user._brStack);
    $gameTemp.reserveCommonEvent(518+user.actorId());
} else {
    $gameVariables.setValue(281 + user.index(), user.name());
    $gameVariables.setValue(284 + user.index(), user._brPotency * user._brStack);
    $gameTemp.reserveCommonEvent(520+user.index());
}
//Remove 'BurnBlock' after 'Burn' proc
...

EDIT: its a good habit to keep the console open when testing these things. It would have said that theres an error in calling user.actorId() on something without that function
It doesn't really work. It fails to record the values. Also it records false numbers for actors, so yeah, I'd rather just figure out how to make game detect troop index for user.
1717354147137.png
so yeah, I'd rather just figure out how to make game detect troop index for user.
thats exactly what its doing for the enemies. the index function returns their index number. you already have sequential variables, so instead of explicitly typing out what to do in each case you can just add a little math to automatically assign variables

Also it records false numbers for actors
what does it display for actors?

It doesn't really work. It fails to record the values
did you see the variable values from the common event, or the console? I did make a mistake with the enemy common events. the last line for the else block should have 521, not 520. so the wrong common events would be playing for enemies, but the variable assignments should have still been correct

otherwise, ive just tested the code. in a 2 actor, 3 enemy fight, i added the state to everyone turn 0. after the first turn: vars 277 and 278 are actor 1 and 2's names, 279 and 280 are 2, 281-283 are enemy 1,2 and 3's names, and 284-286 are 2. which sounds correct looking at what you wrote. this is what it looks like for me as is
Spoiler
Code:
if (!user.isStateAffected(47)) { //removed variable check for testing purposes. add it back
    //Proc burn damage
    user.gainHp(Math.ceil(user._brPotency * user._brStack * -1));
    user._brStack += 1;
    user.addState(47)
    //Get user name for combat log
if (user.isActor()) {
    $gameVariables.setValue(276 + user.actorId(), user.name());
    $gameVariables.setValue(278 + user.actorId(), user._brPotency * user._brStack);
    $gameTemp.reserveCommonEvent(518+user.actorId());
} else {
    $gameVariables.setValue(281 + user.index(), user.name());
    $gameVariables.setValue(284 + user.index(), user._brPotency * user._brStack);
    $gameTemp.reserveCommonEvent(521 + user.index());
}
    //Get Potency / 3 for further application
    $gameVariables.setValue(69, Math.ceil(user._brPotency / 3));
    //$gameTemp.reserveCommonEvent(524);

    //Remove 'BurnBlock' after 'Burn' proc
    if ($gameVariables.value(155) < 4) {
    user.removeState(47);
    }
}
1717362501550.png
However, i use MV. i used the mv equivalent for the tags, but MV's engine doesnt allow for reserving consecutive common events and im not sure if MZ's does as well. i commented out the last one for that reason

it might also be worth noting that your initial turn end tag has mismatched braces. the first brace doesnt have a closing one.
Ok yeah it works now thank you a lot <3

Original thread: https://forums.rpgmakerweb.com/threads/problems-checking-for-enemy-index.169206/