Trying to make a few variables increase when a character dies

Okay to just simplify things at this point, I'm going to give the most recent update and code here and remove all the other stuff I wrote before. The problem is now back to unfixed but there's progress status.

Below is the code. The game variables are "sadness" variables for two other actors. The switch triggers
a common event where the characters are all mourning the character killed. So for each of my actors they have a hidden state similar to this with just game variables and switches triggered.

As I have it now it sort of works. The sytax and way intended works. What should happen is that when a character is killed in battle, the other characters sadness variables go up and they mourn that character via a dialogue that plays. dialogue is triggered by a switch which turns on a common troop event.

Right now, the only problem left to figure out is how to get it to trigger when a character is killed but not when they're already dead. I tried mimicking code from an earlier thread here

I have a respond effect when an attack kills them. I have a regenerate effect that does the same thing only when they are killed by poison or if the character pays health to do it. Only problem now is the regenerate effect is triggering if a character is already dead and a new battle starts and it seems like I can't have it both ways. Any suggestions here, or am I just going to need to pick one or the other at this point?

Code:
<Custom Battle Effect>
user.sadHit = false;
</Custom Battle Effect>
<Custom Respond Effect>
if (target.isDead() && !target.sadHit && target.actorId()==1)
{
    target.sadHit = true;
    $gameVariables.setValue(77,
    $gameVariables.value(77) + 20);
    $gameVariables.setValue(83,
    $gameVariables.value(83) + 20);
    $gameSwitches.setValue(101,
    !$gameSwitches.value(101));
}
else if (!target.isDead() && target.sadHit)
{
    target.sadHit = false;
    $gameSwitches.setValue(101,
    !$gameSwitches.value(101));
}
</Custom Respond Effect>
<Custom Regenerate Effect>
if (target.isDead() && !target.sadHit && target.actorId()==1)
{
    target.sadHit = true;
    $gameVariables.setValue(77,
    $gameVariables.value(77) + 20);
    $gameVariables.setValue(83,
    $gameVariables.value(83) + 20);
    $gameSwitches.setValue(101,
    !$gameSwitches.value(101));
}
else if (!target.isDead() && target.sadHit)
{
    target.sadHit = false;
    $gameSwitches.setValue(101,
    !$gameSwitches.value(101));
}
</Custom Regenerate Effect>
Did you solve the new problem you mentioned as well?
Yep I got it now. Sorry
Actually...you still have a mistake in your code
JavaScript:
target.isDead() // correct
target.isDead   // wrong
...oh really? I wonder why it's still working then? I'll check it when I'm back at PC to make sure I put in here correctly.

Could be one of those things that seems to be working fine now but months later causes a problem I didn't even know I had. So if so...thank you.
...oh really? I wonder why it's still working then?
Because if you put a method into a conditional without the parentheses, you're asking "does this exist as a part of the object?" and the answer is "yes, the Game_Actor has a thing called isDead" so it will always be true.
Oh I see. I was testing by having the enemies one shot the characters so the way the code is now would trigger even if the enemies didn't kill the target. That's why it appeared that be working for me.

Thank you both for catching that!
Well, so I went back and saw for myself what you guys were talking about. I fixed the parenthesis but now it's not triggering at all again.

Edit: fixed it again. Had placed an extra parenthesis unintentionally elsewhere. This is getting quite comical.

However, there is still one more thing to iron out. If a character is already dead, and I start a new battle, the regenerate effect trigger hits and the variable triggers when it shouldn't. If, however I remove the regenerate effect and just leave the respond effect, I can't account for poison effects or moves that involve paying life.

maybe some way to change the flag trigger for "sadHit"?

Okay: so I made a slight change. I declared sadHit but left it undefined.

So now the top tag reads

<Custom Battle Effect>
user.sadHit;
</Custom Battle Effect>

and...it seems to work now. I haven't tried healing and seeing if it triggers again after healing and killing them, but this might solve it? Are there any unintended consequences I should know about doing it this way?

Original thread: https://forums.rpgmakerweb.com/threads/trying-to-make-a-few-variables-increase-when-a-character-dies.166959/