Saving Mouse Position to Variables?

What I'm looking for is a way to store the X position of the mouse cursor to one variable and the Y position of the mouse cursor to another. Not the coordinates of where the mouse has clicked, just the coordinates of where the cursor currently is.

I've seen this question asked like a million times before with slight variations and tried scouring through all of those threads for a working solution, but I personally have never found anything that has even begun to function for me in any of them. Any help would be appreciated because at this rate it's driving me nuts how hard it has been to find a way to do this!
Hi there!
See if this little snippet will help you.
Open the file with any text editor and:
  • Replace IDX with the variable ID you will store the X coordinate.
  • Replace IDY with the variable ID you will store the Y coordinate.
Oh my god that worked like a charm! Thank you @Eliaquim, you're a life saver!
Note, the above will give you the mouse coordinates in pixels relative to the top left of the screen. So the top left will be 0,0 and the bottom right will be 768,512 if that is your window size.

If you wanted the actual map coordinates, more would be required.
I'm fine with having the mouse position in pixels, but if I ever need to change it over to tiles I feel like I could make something work with this.
Hi there!
See if this little snippet will help you.
Open the file with any text editor and:
  • Replace IDX with the variable ID you will store the X coordinate.
  • Replace IDY with the variable ID you will store the Y coordinate.

Hello Eliaquim, I'm using this plugin in my rpg maker mz project, it's working, but when I start the game test and move the mouse across the screen it gives me the following error: "Uncaught TypeError: Cannot read property 'setValue' of null ".

Screenshot_5.png
Screenshot_4.png


But if I start moving the mouse on the title screen or inside the game this error does not appear, only when I move when I start the playtest even in the first seconds that the screen opens, Do you have a solution to solve this 'small' problem? I really don't know how.
Screenshot_6.png
Hello Eliaquim, I'm using this plugin in my rpg maker mz project, it's working, but when I start the game test and move the mouse across the screen it gives me the following error: "Uncaught TypeError: Cannot read property 'setValue' of null ".

View attachment 246497View attachment 246496

But if I start moving the mouse on the title screen or inside the game this error does not appear, only when I move when I start the playtest even in the first seconds that the screen opens, Do you have a solution to solve this 'small' problem? I really don't know how.
View attachment 246499
Hi there!
I guess it's because the $gameVariables are not created yet.
On line 5, insert the following:
if($gameVariables){
// Put here the two lines of game variables(Line 5 and line 6).
}
Hi there!
I guess it's because the $gameVariables are not created yet.
On line 5, insert the following:
if($gameVariables){
// Put here the two lines of game variables(Line 5 and line 6).
}
It worked perfectly, thank you 😀

Original thread: https://forums.rpgmakerweb.com/threads/saving-mouse-position-to-variables.143945/