What is the current X Y position of battler

I'd like to save the position of the active battler in two variables, because I would like the battle command menu to be directly above the current battler.
I'm struggling since battler.spritePosX gives me the same value for all battlers, and it's wrong.

I tried to draw the battle screen to explain it. the menu should change places, and always be there where the currently active battler is standing. (1, 2, 3...)

Anyone has a clue how to do get those x y values?
generically, as I don't have the javascript equivalent:
Code:
spriteset_battle.battler_sprites.filter(sprite, index){sprite.battler == $game_party[index]}[index2].position

the sprites are held within the spriteset, but there's no direct access to the actors sprites within that spriteset.
you have to bring the whole spriteset via battler_sprites, filter out the actors by comparing with the party via the "battler" property of each sprite (index), and from that set, obtain the position of each one (index2), which is one call for X and another for Y, if they're not returned as a set.
There is a difference between the battler (Game_Battler) and its sprite (Sprite_Battler).

If you have the sprite, check its _homeX and _homeY properties:
Code:
sprite._homeX


If you have the battler, you'll need some form of lookup to retrieve the associated sprite. If you're using Yanfly's Battle Engine Core plugin, there's a handy "battler" function that does this for you, so you can do this sort of thing:
Code:
battler.battler()._homeX
Otherwise you'll need your own lookup, like gstv87 suggests, e.g. something like this in a Script command:
Code:
var battler = $gameTroop.members()[0];  // enemy troop leader
var sprite = null;
SceneManager._scene._spriteset._enemySprites.some(function(sp) {
  if (sp._battler === battler) {
    sprite = sp;
    return true;
  }
  return false;
});
$gameVariables.setValue(1, sprite ? sprite._homeX : -1);
$gameVariables.setValue(2, sprite ? sprite._homeY : -1);
^ This should loop through the enemy sprites looking for the one corresponding to member 0 of the enemy troop. Then it'll set game variables 1 & 2 to the X & Y coordinates of that sprite (or -1 if sprite is undefined, just in case).
Thank you both, the second code works but only for the first battler.
For some reason, the values don't update when the second battler comes on. The x and y always stay the same. What am I doing wrong?
It depends somewhat on how you're using it...are you writing a plugin?

This line of the script call I provided determines which battler is checked:
Code:
var battler = $gameTroop.members()[0];
The 0 here means "first enemy in the troop", i.e. the troop leader. To check a different enemy, change this value; e.g. for second enemy in the troop use 1 instead. You may have access to the selected index, in which case you can just use that in place of the 0.
EDIT: Nevermind, the first line worked!

Thank you so much!!!!!!!!!!! 🙂

Original thread: https://forums.rpgmakerweb.com/threads/what-is-the-current-x-y-position-of-battler.111278/