MV mouse position issue

hello i am trying to save mouse position in variables x,y and then assign it to a variables in game but i get this error.

JavaScript:
 TouchInput._onMouseMove = function(event)
{
        var x = Graphics.pageToCanvasX(event.pageX);
        var y = Graphics.pageToCanvasY(event.pageY);
        $gameVariables.SetValue(10,x);
        $gameVariables.SetValue(11,y);
 };

10 and 11 are the variables in the game.

error.png


any solution?
hello i am trying to save mouse position in variables x,y and then assign it to a variables in game but i get this error.

JavaScript:
 TouchInput._onMouseMove = function(event)
{
        var x = Graphics.pageToCanvasX(event.pageX);
        var y = Graphics.pageToCanvasY(event.pageY);
        $gameVariables.SetValue(10,x);
        $gameVariables.SetValue(11,y);
 };

10 and 11 are the variables in the game.

error.png


any solution?
A couple things...

Because your modifying a core file, the "_onmouseMove" function/event occurs before $gameVariables is ever declared ...so the easiest fix was just to simply add an if statement to check whether $gameVariables exists before trying to set a value to a game variable

the second issue would be the capital 'S' on the "setValue" function of $gameVariables it is a lowercase 's'

Made a plugin for you though 🙂
Should do exactly as you need 🙂
1651623321082.png

Seems to work perfectly with the little bit of testing I just did.

Hope that helps.
A couple things...

Because your modifying a core file, the mouseMove event occurs before $gameVariables is ever declared and then the second issue would be the capital 'S' on the "setValue" function of $gameVariables. It is a lowercase

Made a plugin for you though 🙂
Should do exactly as you need 🙂

I already solved it, the s of setValue should be lowercase haha, how silly.
I already solved it, the s of setValue should be lowercase haha, how silly.

thanks, I want to use those variables to move an object with the mouse from one tile to another but it doesn't work for me because the script assigns values to the mouse outside the map (when the map is very small).

How do I assign values to the mouse that are inside the map? not game window but the map in the game.
that is, I must convert pixels to tiles, how do I do that?
thanks, I want to use those variables to move an object with the mouse from one tile to another but it doesn't work for me because the script assigns values to the mouse outside the map (when the map is very small).

How do I assign values to the mouse that are inside the map? not game window but the map in the game.
Made an update to allow you to only choose to store to variables on maps/specific maps via notetags

Spoiler: Plugin Parameters/Features
1651626723887.png


If using the map note tag feature it would be setup like this:
1651626925476.png

<Touch_To_Variables:true>

that is, I must convert pixels to tiles, how do I do that?

@isaias20
That would be like this
JavaScript:
$gameMap.canvasToMapX($gameVariables.value(10))
$gameMap.canvasToMapY($gameVariables.value(11))

that works perfectly 🙂
Made an update to allow you to only choose to store to variables on maps/specific maps via notetags

Spoiler: Plugin Parameters/Features
View attachment 225047

If using the map note tag feature it would be setup like this:
View attachment 225048
<Touch_To_Variables:true>



@isaias20
That would be like this
JavaScript:
$gameMap.canvasToMapX($gameVariables.value(10))
$gameMap.canvasToMapY($gameVariables.value(11))

that works perfectly 🙂


In which line of the plugin should I place those two lines?
In which line of the plugin should I place those two lines?
Another update for ya 😉
1651627638827.png



Should work exactly as needed ☺️
Another update for ya 😉
View attachment 225049


Should work exactly as needed ☺️


works perfect, thanks.

Now I am trying to move an event with mouse by placing these options on page 2 in parallel processing.

move item.png


But the event passes through other events and walls. Is there a way to move the event so that it collides with the other events? I don't want it through the wall either.

Thank you.
works perfect, thanks.
Wooo no prob. Glad to hear it's working as needed. ☺️

Now I am trying to move an event with mouse by placing these options on page 2 in parallel processing.

View attachment 225050

But the event passes through other events and walls. Is there a way to move the event so that it collides with the other events? I don't want it through the wall either.

Thank you.
You can do something like this...
Spoiler
1651629059275.png

That will make it so the event will not move to any place that is an obstacle.

...for border walls since they aren't marked as non passable.. I had to use a region ID
in the example I chose to use region ID #5

...soo the setup for that was like this:
Spoiler
1651629076169.png
& this is the conditional script code used:
JavaScript:
$gameMap.isPassable($gameVariables.value(10),$gameVariables.value(11)) && $gameMap.regionId($gameVariables.value(10),$gameVariables.value(11)) !== 5

Here's what that looks like in-game:
Wooo no prob. Glad to hear it's working as needed. ☺️


You can do something like this...
Though I'm not certain that will still give you the exact result your hoping for
but it will not move the event to any place that is an obstacle.

...for border walls since they aren't marked as non passable.. I had to use a region ID
in the example I chose to use region ID #5

...soo the setup for that was like this:
& this is the conditional script code used:
JavaScript:
$gameMap.isPassable($gameVariables.value(10),$gameVariables.value(11)) && $gameMap.regionId($gameVariables.value(10),$gameVariables.value(11)) !== 5

Here's what that looks like in-game:


Maybe that's at least somewhat helpful?


works perfect, thank you very much!
works perfect, thank you very much!
Woooo! Very welcome ☺️ 👍
Glad to help out 🙂

Happy Game Making! :LZSgrin:
Hello, is there a way to do this in mz?

Original thread: https://forums.rpgmakerweb.com/threads/mouse-position-issue.147297/