MZ How to express the home position of the current battler in script?

I want to use action sequences to make one character's home position based on another character's relative position, but I don't know how to get the home position of the previous character.
I don't know much about how action sequences work in visustella's plugin/s, but if you are allowed to input code to some degree it's only a matter of having the 2 battlers in question then you can use the BattleManager.spriteset to get the battler sprite of each.
In order to get the battler sprite of a battler you can use the "findTargetSprite" method from within the spriteset.

BattleManager.spriteset.findTargetSprite(target);
"target" being something like $gameParty.battleMembers()[0] for example.

Battler sprites have a "_homeX" and a "_homeY" property to determine their home positions, if you have access to the sprite of a battler then you can use "setHome" method to change their home position.


battlerSprite1.setHome(battlerSprite2._homeX, battlerSprite2._homeY);
"battlerSprite" being the sprite/s you get from the "findTargetSprite" method mentioned before.
I don't know much about how action sequences work in visustella's plugin/s, but if you are allowed to input code to some degree it's only a matter of having the 2 battlers in question then you can use the BattleManager.spriteset to get the battler sprite of each.
In order to get the battler sprite of a battler you can use the "findTargetSprite" method from within the spriteset.

BattleManager.spriteset.findTargetSprite(target);
"target" being something like $gameParty.battleMembers()[0] for example.

Battler sprites have a "_homeX" and a "_homeY" property to determine their home positions, if you have access to the sprite of a battler then you can use "setHome" method to change their home position.


battlerSprite1.setHome(battlerSprite2._homeX, battlerSprite2._homeY);
"battlerSprite" being the sprite/s you get from the "findTargetSprite" method mentioned before.
I'm still a bit confused, could you please explain with an example? For instance, how would I write a script to input the X coordinate into variable 29 using a common event?

I'm quite new to scripting, and I've been using AI to help analyze and teach me the logic behind it, allowing me to complete some scripting tasks to a certain extent, but I still lack a lot of foundational knowledge.

This issue arose while I was creating a summoning skill. I need to obtain the home position of the character whose turn it is to act. With the home position's X and Y coordinates, I can adjust the summoned creature's position relative to the summoner's home position through an action sequence.

Ideally, the actor is determined dynamically rather than by their ID or order in the party, which allows the summoning skill to be more flexibly assigned and not bound to a specific character's ID.
I've been using AI to help analyze and teach me the logic behind it...but I still lack a lot of foundational knowledge.
I suggest instead of trying to do it via AI, you use an actual tutorial written by a person who knows what they're doing (or a book, or a course, etc.).

I like w3schools, starting with the Statements chapter, but you have many options out there created by people with training.
I suggest instead of trying to do it via AI, you use an actual tutorial written by a person who knows what they're doing (or a book, or a course, etc.).

I like w3schools, starting with the Statements chapter, but you have many options out there created by people with training.
Thank you very much for your suggestion, and I completely agree with it. I'm just not ready yet and am currently in the early stages of learning, before embarking on a systematic study.

I have no intention of belittling formal education, and I have the utmost respect for anyone who has achieved expertise in a particular field. However, this is a field I have never been exposed to before, and I find myself with many questions when going through tutorials. Some of these questions might seem basic to a professional, but they aren't always easily answered through search engines or flipping through books, and sometimes I don't even know the correct terminology to use to find answers.

A silly example is that for the first two days, I didn’t even know that scripts had to be separated by spaces. No one emphasized this, as it seems to be a piece of knowledge so basic that everyone assumes it doesn't need to be mentioned. Of course, after understanding this, I realized it was my own lack of knowledge. But as a beginner with no innate talent in this area, I do feel helpless at times due to issues like this when trying to learn.

Interacting with GPT gives me clear annotations, helps me understand what each part of the script is doing, and allows me to dig deep into every detail that confuses me. In real life, it's not feasible to frequently disturb a professional with such basic questions, considering everyone has their own work and life.

Consulting with AI has indeed helped me transition from being completely clueless about scripting to starting to understand some basic principles, and gradually being able to complete some simple tasks independently.

I don’t see it as a shortcut to bypass formal learning, but rather as a stage before embracing professional knowledge. After accumulating a certain level of understanding, I believe I will be more capable of comprehending those tutorials that previously confused me, and truly begin the learning process. But before that, I need some help that suits my current level.
Ideally, things like that should be addressed. For example, I assume that by "scripts had to be separated" you mean that each word of code has to be separated by a space.

That is, in fact, addressed in the very tutorial that I recommended to you. Every example given on the page (and it has fields for you to type it back in) has spaces in the appropriate places. And it even specifies:
1706754255249.png


So it shows you where a space is relevant and where it isn't.

Anyhow, my point was simply that following a linear course of study will, eventually, teach you the answers to your questions (and if it doesn't, it's easy to ask. There's a specific section of this forum called Learning JavaScript, and even a pinned thread for small questions that don't deserve a thread).

But it will prevent you from saying "I can do these things at this skill level, but I don't know these other basic things because I never thought to ask about them."

how would I write a script to input the X coordinate into variable 29 using a common event?
Inside a VisuStella Action Sequence, you could use this command to store the acting battler's home X coordinate:
Code:
$gameVariables.setValue(29, BattleManager.spriteset.findTargetSprite(user)._homeX)
Ideally, things like that should be addressed. For example, I assume that by "scripts had to be separated" you mean that each word of code has to be separated by a space.

That is, in fact, addressed in the very tutorial that I recommended to you. Every example given on the page (and it has fields for you to type it back in) has spaces in the appropriate places. And it even specifies:
View attachment 293738

So it shows you where a space is relevant and where it isn't.

Anyhow, my point was simply that following a linear course of study will, eventually, teach you the answers to your questions (and if it doesn't, it's easy to ask. There's a specific section of this forum called Learning JavaScript, and even a pinned thread for small questions that don't deserve a thread).

But it will prevent you from saying "I can do these things at this skill level, but I don't know these other basic things because I never thought to ask about them."


Inside a VisuStella Action Sequence, you could use this command to store the acting battler's home X coordinate:
Code:
$gameVariables.setValue(29, BattleManager.spriteset.findTargetSprite(user)._homeX)

If I have previously shown any offense to the technicalities, please forgive me, it was never my intention.

Yes, I mean each word of code. You corrected my incorrect terminology.

Why shoule I say 'I never thought to ask about them' ?
Having a place to ask questions is a great thing,
I always have questions, and I long for someone to answer them.


I just ran into a problem while testing the script you taught me.

I executed the script using a common event, made it into a skill, and had a character perform it in battle, but its change to the variable was always 0.

So I added a control group in this common event like this:

未命名图片4.png



The tests proved that only the control group was effective.

I also tested splitting it into two scripts, and the result was the same.

未命名图片5.png



Later, I tried to troubleshoot by turning off all plugins in a new project and then turning them on one by one. However, I found that without the Visu core engine, it would only cause the game to crash.

未命名图片6.png


Turning on other plugins one by one only yielded the same result as before.

I know something is wrong, but I don't know where the problem lies.

I have another question,

I don't know if the home position of the first character is (0,0),

So I placed the character who executes this event in the second position instead of the first, and the result is still 0.

I'm starting to doubt if I'm asking the right questions. What exactly is the home position?

Is it what I'm looking for?

Is it the coordinate used to represent the position of each character in the global battlefield, as I previously thought?

Or is it default to (0,0) for each character, used to calculate the relative displacement when using skills?

Should I move to the pinned thread of Learning JavaScript, or continue to ask questions in this post?
Oops, i forgot that "spriteset" is supposed to be a private property so i forgot to add a "_" before it, like so:
JavaScript:
BattleManager._spriteset.findTargetSprite(user)._homeX;
BattleManager._spriteset.findTargetSprite(user)._homeY;

As for you second question, by default there's no way for a character position to be x: 0, y: 0, reason being this formula, where "index" will represent your first, second, third, etc character accordingly.
JavaScript:
Sprite_Actor.prototype.setActorHome = function(index) {
    this.setHome(600 + index * 32, 280 + index * 48);
};
The home position is like the origin of a battler in battle, this is important because the way movement works is that there's an offset added to the battler with a set duration:

JavaScript:
// Tell the battler to move x and y pixels for a set duration.
// Do keep in mind that this takes into consideration the battler's home position
Sprite_Battler.prototype.startMove = function(x, y, duration) {
    if (this._targetOffsetX !== x || this._targetOffsetY !== y) {
        this._targetOffsetX = x;
        this._targetOffsetY = y;
        this._movementDuration = duration;
        if (duration === 0) {
            this._offsetX = x;
            this._offsetY = y;
        }
    }
};

// How the movement is proccessed in battle
Sprite_Battler.prototype.updateMove = function() {
    if (this._movementDuration > 0) {
        const d = this._movementDuration;
        this._offsetX = (this._offsetX * (d - 1) + this._targetOffsetX) / d;
        this._offsetY = (this._offsetY * (d - 1) + this._targetOffsetY) / d;
        this._movementDuration--;
        if (this._movementDuration === 0) {
            this.onMoveEnd();
        }
    }
};

// How the battler's actual position is decided
// Home Position(this._homeX, this._homeY) being the origin position
// Movement Offset(this._offsetX, this._offsetY) how much the battler has moved
Sprite_Battler.prototype.updatePosition = function() {
    this.x = this._homeX + this._offsetX;
    this.y = this._homeY + this._offsetY;
};
Oops, i forgot that "spriteset" is supposed to be a private property so i forgot to add a "_" before it, like so:
JavaScript:
BattleManager._spriteset.findTargetSprite(user)._homeX;
BattleManager._spriteset.findTargetSprite(user)._homeY;

As for you second question, by default there's no way for a character position to be x: 0, y: 0, reason being this formula, where "index" will represent your first, second, third, etc character accordingly.
JavaScript:
Sprite_Actor.prototype.setActorHome = function(index) {
    this.setHome(600 + index * 32, 280 + index * 48);
};
The home position is like the origin of a battler in battle, this is important because the way movement works is that there's an offset added to the battler with a set duration:

JavaScript:
// Tell the battler to move x and y pixels for a set duration.
// Do keep in mind that this takes into consideration the battler's home position
Sprite_Battler.prototype.startMove = function(x, y, duration) {
    if (this._targetOffsetX !== x || this._targetOffsetY !== y) {
        this._targetOffsetX = x;
        this._targetOffsetY = y;
        this._movementDuration = duration;
        if (duration === 0) {
            this._offsetX = x;
            this._offsetY = y;
        }
    }
};

// How the movement is proccessed in battle
Sprite_Battler.prototype.updateMove = function() {
    if (this._movementDuration > 0) {
        const d = this._movementDuration;
        this._offsetX = (this._offsetX * (d - 1) + this._targetOffsetX) / d;
        this._offsetY = (this._offsetY * (d - 1) + this._targetOffsetY) / d;
        this._movementDuration--;
        if (this._movementDuration === 0) {
            this.onMoveEnd();
        }
    }
};

// How the battler's actual position is decided
// Home Position(this._homeX, this._homeY) being the origin position
// Movement Offset(this._offsetX, this._offsetY) how much the battler has moved
Sprite_Battler.prototype.updatePosition = function() {
    this.x = this._homeX + this._offsetX;
    this.y = this._homeY + this._offsetY;
};
Thank you very much for your patient explanations!
I couldn't figure out how to successfully read the current character's homeX and homeY using scripts and don't know why,
so I found an alternative solution to work around this issue.
Nevertheless, your explanations of the underlying logic have been incredibly helpful to this novice!

Original thread: https://forums.rpgmakerweb.com/threads/how-to-express-the-home-position-of-the-current-battler-in-script.165324/