Pulling Variables with a script

Hello,

I saw the code lists and needed a bit of help. I'm not fully sure how a lot of this coding works.

Basically, I am using one of the visustella mods which change EXP for enemies based on random multipliers. I'm trying to find a code that when the battle starts it pulls the current XP totals for all the enemies in the battle, and save them as a variable so I can do stuff with the variable to post the number in the victory screen. I can't seem to figure out which code to use to pull the current data for a battle, within the battle. Any help would be appriciated! Thank you!!

-Pip
You could do something like

$gameVariables.setValue(1, $gameTroop.members().reduce((acc, enemy) => acc += enemy.exp(), 0));

That will store the total experience for all enemies in the troop in game variable 1.

Though if it's for the victory screen, $gameTroop already has an expTotal() function you can call to get the total exp for all dead enemies, rather than the total for the troop as a whole.
I see. Well my problem is, I'm trying to do math before the end of battle to display the actual current XP earned due to the character's getting exp upgrades through the game. The victory screen only displays the enemy exp but doesn't calculate the actual exp earned for the party. So I use the variable during battle to do math duing it so I can display the exp correct EXP in the victory screen.
Though that code seems to have worked beautifully. Yeah, there is no way I would have figured that out.
Double-post notice: @pipbrit

If your question is solved now, please report your thread and say so, and it will be closed.

Thread closed

Original thread: https://forums.rpgmakerweb.com/threads/pulling-variables-with-a-script.137271/