Get the grid position

Hi,

I try to take the grid position on the map. I have succesfull to take the pixel position in many way but for take the grid position arrrrgh.

I try to make a game or when i click on event with the mouse I "select" this event ( with TDD mouse ), i can move this event on other point on the map with the mouse. My idea is to collect the grid position for swith after the event with the hero loc. But i will try to optimize this with the yanfly plugin for disable move hero and teleport simply the event where i click.
I will try after to limited the movement teleport at few grid but i think i will found it.
Difficult for me to explain in English, I hope than you have understood and than you can help me; Thx 🙂
Ehm I hope I understand what you are trying to do:
Get the player location: Set 2 Variables. 1 for PlayerX and 1 for PlayerY. In both PlayerX and Y go to Game Data instead of the default (constant) and click on Map ID. Now click on Character and select Map X or Map Y depending on the Variable.
For specific script calls take a look here:

Don't know if TDD mouse already can determine the tile location but if it can't, maybe you can spawn a parallel event where the player clicks with Galv Event Spawner and directly determine that events' location just like I wrote above, but with choosing Map X or Map Y you'll also have to select "this event".

Hope this helps...
Thanks its not really that but with he Map X or Y i can see the location. I have see on script call yesterday and i dont found.

I make an example : I have an event called A, on ( 12, 6 ) on the grid. I click on A to activate A ( with my script ). I click on ( 12, 12 ) A is teleported here. I click again on ( 6 , 6 ) A is teleported again in the grid.

But for that I need to have the cordinate of my mouse when I click on ( 12, 12 ) or everywhere. But if I cant have the final destination I have only the depart point of my event, no the finish.
I need something $gameVariables.setValue(17,TouchInput._x); but TouchInput._x) give me the pixel loc, if you have the same with grid its perfect.
Sounds like something TDD would know as I don't have any experience regarding the plugin. You can contact him via his site (if he has one at least) or maybe start a conversation on this forum
But the plugin is not very important for have the line code to wrote in script for store the grid position.
It is if you want the exact location of your mouse. And besides that, I don't know if the plugin knows you're talking about the mapXy or the ScreenXy
No, i repeat, forget the plugin xD
I want just to knows the mapXy or my mouse, without plugin, the most simplify possible.
Well I'm afraid that ain't possible with just a script call if it isn't in the list. That's why you'll need a, or the, plugin with a plugin command to do such a thing.
Since MV has mouse input by default, there should be something in its base JS files, so I took a look and found TouchInput inside the rpg_core.. Based from that

Try

TouchInput._x
TouchInput._y

if it gives you the pixel x,y just divide them by the tile size (48 normally) to get which grid tile they are on.

@Arend Galenkamp - that list only summarizes the Script Call equivalent of event commands and some other script calls deemed useful. It is not a full list of all possible script calls from the default engine.
If I understand correctly you want to get the tile x and tile y of a mouse click and save it to a variables.

If so, use a placeholder event on tile (0, 0) then use this code:

Code:
var x = TouchInput.x;
var y = TouchInput.y;
x = Math.abs(Math.floor(x/48));
y = Math.abs(Math.floor(y/48));
x -= Math.abs(Math.floor($gameMap.event(id).screenX()/48));
y -= Math.abs(Math.floor($gameMap.event(id).screenY()/48));
$gameVariables.setValue(idx, x);
$gameVariables.setValue(idy, y);

Where:
id = id of the placeholder event on tile (0,0).
idx = id of variable you want to save x tile position to.
idy = id of variable you want to save y tile position to.

This will save the map x and y of the last place clicked by the mouse into those two variables for later use.

I assume you'll be running this with a parallel event - I would consider using a conditional branch set with the script

Code:
TouchInput.isTriggered()

This will save those values being set to the variables unnecessarily, potentially reducing lag.
There's a function already written for it:

Code:
$gameMap.canvasToMapX(x);
$gameMap.canvasToMapY(y);
There's a function already written for it:

Code:
$gameMap.canvasToMapX(x);
$gameMap.canvasToMapY(y);
Would that also work if the game only runs in WebGL? Or am I mixing up 2 things.
Works either way, it's how the game figures out which tile you clicked/pressed on when you do player movement with mouse/touch. Canvas in that function name refers to the x,y position on the HTML <canvas> element, not the rendering style of canvas-rendering vs. WebGL-rendering.

Original thread: https://forums.rpgmakerweb.com/threads/get-the-grid-position.106469/