MZ how to show total damage done to enemy as a variable

.. I am still getting print outs of 0...

<Custom Action Sequence>

<JS Post-Damage as User>
target.damageDealt = target.damageDealt || 0;
target.damageDealt+=value;
</JS Post-Damage as User>

^ that is in my skill note box

and the attached picture is how I am trying to set value to the variable...
I also tried $gameVariables.value(141) == value


I didn't take note of what it was.. but something I tried printed out the variable as True instead of 0...
and the attached picture is how I am trying to set value to the variable...
There's a fair bit wrong with that attempt. I'll detail stuff for you, but I don't know how much you're trying to learn JavaScript, so feel free to skip over it if you're just looking for a solution.

1 - You can't say "something = something else += another thing". = and += are both assignment operators, so you're trying to put another left-hand argument into the right-hand side. You would just say "something = something else + another thing"

2 - RPG Maker has no idea what "target" is. As we've mentioned previously (and it says in the plugin documentation), "target" is a variable created by your VisuStella plugins for use in various notetags. It's internal to those notetags and can't be just used wherever you like. Trihan gave you one example of how you could reference a battler outside of a notetag.

I also tried $gameVariables.value(141) == value
3 - I don't even know what you're trying to do here. 😛 == is checking equality between two things, and it returns a boolean value - true or false.

4 - If you're trying to make variable 141 equal your accumulated value, Trihan went over this in post #20 - the $gameVariables.value() method returns a value. You can't use it to set a variable's value. That's $gameVariables.setValue().

4a - You seem to have a fair bit of confusion about operators. This is something very basic that you want to have a grasp of it you're trying to learn some JavaScript. Most of them are the same as you learned in regular math, so all of the new things you might use regularly in code are assignment operators.

If you're intent on using a game variable for this, there's no reason to create a variable on the battler at all. Just modify the notetag I gave you with the game variable functions Trihan explained to you and you're all set.

Code:
<JS Pre-Start Action>
$gameVariables.setValue(141, 0);
</JS Pre-Start Action>

<JS Post-Damage as User>
$gameVariables.setValue(141, $gameVariables.value(141)+value);
</JS Post-Damage as User>
<_< I had just started a class.. but am very early on.
The information is very appreciated and I'm gonna finish the class and prob take a few others.. but atm I have pretty bare bones understanding >O>

... also unless I messed something up again... you're saying I just need this in my skills note tag?
Code:
<Custom Action Sequence>

<JS Pre-Start Action>
$gameVariables.setValue(141, 0);
</JS Pre-Start Action>

<JS Post-Damage as User>
target.damageDealt = target.damageDealt || 0;
target.damageDealt+=value;
$gameVariables.setValue(141, $gameVariables.value(141)+value);
</JS Post-Damage as User>

doing so still is printing out 0 when I try to call variable(141) Dx
I GOT IT TO WORK!

Code:
<Custom Action Sequence>

<JS Pre-Start Action>
$gameVariables.setValue(141, 0);
</JS Pre-Start Action>

<JS Post-Damage>
target.damageDealt = target.damageDealt || 0;
target.damageDealt += value;
$gameVariables.setValue(141, $gameVariables.value(141)+value);
</JS Post-Damage>

Needed to switch it to Post-Damage instead of Post-Damage as User.... post damage as user can't be used on skill note tags... >O>
... also unless I messed something up again... you're saying I just need this in my skills note tag?
No, that is different from the code I just gave from you. Instead of copying and pasting it, you added two lines that I said were unnecessary:
If you're intent on using a game variable for this, there's no reason to create a variable on the battler at all.

That said, those two lines of code also aren't doing anything 😛

My guess is that the "value" variable doesn't actually exist in the Post-Damage notetag. Unfortunately, the VisuStella documentation doesn't say where it works.

(in fact, it doesn't mention its existence at all, people who used the older Yanfly plugins are just able to guess)

So try changing the notetag to read Pre-Damage instead of Post.

Ninja: I saw your post about the notetag, that was my mistake. Please note that we're not supposed to double post. If you need to add something, you can click the Edit button.

I'm glad you got it working - good luck with your project.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-show-total-damage-done-to-enemy-as-a-variable.154860/