Q: I want to check the position of Player and compare with the position at side of Events

I pulled that title from the MV script call list line 162. They give these script calls:


$gameVariables.setVariable(6, $gamePlayer.x)
$gameVariables.setVariable(7, $gamePlayer.y)
$gameVariables.setVariable(8, $gameMap.events()[n].x)
$gameVariables.setVariable(9, $gameMap.events()[n].y)



Which I set 6,7,8,9 to in game variables and [n] to the events id.


Then they give this script call (what I am trying to accomplish):


$game_variables[7] == $game_variables[9] and ($game_variables[6] - $game_variables[8]).abs == 1


I get TypeError undefind is not a function. I have this screenshot of my "attempt".


Screenshot.png


Sorry if it may be a noob question, but I'd really like to get this to work and have tried everything I can think of.
Hi there.


I don't think script requests are the right way to go here. There are event commands for every single thing you wanna achieve here.


Also, your question isn't very clear, maybe you can rephrase it to further explain what you want to achieve exactly.


Nevermind then 😉  ignore post

Spoiler
Spoiler





You can set variables directly as playerd and/or events positions on the map without using a script:


help1.PNG


Then, to compare the two, insert a "Conditional Branch" command and compare the two variables.


To make multiple comparisons, just stack these conditional branches.


In my example, I compared the X variables first, then the Y variables. When both are true - meaning they have the same value - then something is executed.


help2.PNG


I hope that helped. If you  have further questions, don't hesitate to ask back!





Simon
The word "and" is not a function, that's why you get the error.


Try (untested)


($game_variables[2]===$game_variables[75])&&($gmae_...


(complete as needed, I'm to lazy to write everything ;-) )
I know how to do this with events.I'm trying to find out if they beside each other not on the same tile.


This is what is in the script call list :


If you only want them to be beside the event (positions 1 or 3), use this:
$game_variables[7] == $game_variables[9] and ($game_variables[6] - $game_variables[8]).abs == 1
# which says if the y value is the same and there is a difference of 1 between the x values.
# Note: abs = absolute value


So I'm guessing that means 1 tile next to the event?
Thanks Andar, I know a little of events but nothing of script coding 🙂 opps sorry for double post

Original thread: https://forums.rpgmakerweb.com/threads/q-i-want-to-check-the-position-of-player-and-compare-with-the-position-at-side-of-events.55748/