Event position to another event conditional branch

Hi!
I'm trying to make a soccer/european kickoff minigame and have it almost working but I just wonder if I'm doing anything wrong with the code?
My "Goal": Is that when the football event is 1 tile away from the goalkeeper event he shoots it back out.

My problem: he does that but seems a bit random and sometimes he shoots it out even if he isn't close to the football.
My parallell event setup: event 14 is goalkeeper, event 25 is football.

help football close to goalie.png


Am I doing anything wrong?

Thanks in advance!
I think its the === 1 (which is strictly equal to 1.
try more > 0 and < 2 and see what happend or <= 2
I think its the === 1 (which is strictly equal to 1.
try more > 0 and < 2 and see what happend or <= 2
I will try it out. <3
How exactly should I write it you think? an example or two maybe? 🙂

EDIT: I've tried different solution and none were better than my original === 1

Any other suggestions?
there is another problem in that you combine too many checks into one line.
this creates more positions where the condition is true than you think.

for example the condition is also true when the x distance is 2 and the y distance is -1, because you neither use absolutes nor check x and y differently.
there is another problem in that you combine too many checks into one line.
this creates more positions where the condition is true than you think.

for example the condition is also true when the x distance is 2 and the y distance is -1, because you neither use absolutes nor check x and y differently.
So, how would you have written it? 1tile away/adjecent to each other is what I'm after.
I would have made it two nested if conditions, one checking for the difference between x and one checking for the difference between y, both required that the absolute (which is another javascript function but I don't have the syntax ready) being <=1 (so it can be zero or one).
and both ifs need to be true for the effect.
Here's a reply I posted on a thread for a similar question:
There is a core script function for calculating "X + Y" distance, which also accounts for looped maps:

const c1 = $gamePlayer, c2 = this.character(0); $gameMap.distance(c1.x, c1.y, c2.x, c2.y) < 3
This can be used in Conditional Branch -> Script. I've used this.character(0) here for "This Event", because it's a bit shorter to write.

Alternatively, like Bex implies, this is possible without scripting:
  • Control Variables -> Game Data -> Character -> Map X|Y;
  • Conditional Branch -> Variable.
Here's a reply I posted on a thread for a similar question:
Interesting. I will try this out later!
So this character being the goalie but what is the shortest code of event 25 (being the football)?
You have an example of how the whole event should look or the whole script?
Write it so even a dull person like I gets it
or the whole script?
that was the whole script - you just have to place it into the script line in the conditional branch of your original event.
that was the whole script - you just have to place it into the script line in the conditional branch of your original event.
Looking forward to my next dev session tonight to try it out
So this character being the goalie but what is the shortest code of event 25 (being the football)?
You had that part right in your original script, just use $gameMap.event(25). So, this tests if the distance between event 25 and This Event is 1 tile or less:

const c1 = $gameMap.event(25), c2 = this.character(0); $gameMap.distance(c1.x, c1.y, c2.x, c2.y) <= 1
You had that part right in your original script, just use $gameMap.event(25). So, this tests if the distance between event 25 and This Event is 1 tile or less:

const c1 = $gameMap.event(25), c2 = this.character(0); $gameMap.distance(c1.x, c1.y, c2.x, c2.y) <= 1

I used this piece of wonder you suggested and it works like a charm!
You will get in the credits for this! OH YES YOU WILL!
What do you want to be named in the credits?

THANKS!
Thx.png
You're welcome! "caethyril" or "Caethyril" is OK. 👋
You're welcome! "caethyril" or "Caethyril" is OK. 👋
Noted and saved! 🙂

Original thread: https://forums.rpgmakerweb.com/threads/event-position-to-another-event-conditional-branch.152299/