Mouse Notetags?

I need help finding the mouse notetags

For example:

TouchInput._x

TouchInput._y

those notetags let me access the map coordinates when the mouse is clicked.

Instead I want to access the mouse coordinates, always, even if the mouse is not being clicked

And all the usefull notetags to use as conditional branch for the mouse.

Thanks!
I need help finding the mouse notetags

For example:

TouchInput._x

TouchInput._y

those notetags let me access the map coordinates when the mouse is clicked.

Instead I want to access the mouse coordinates, always, even if the mouse is not being clicked

And all the usefull notetags to use as conditional branch for the mouse.

Thanks!
Please, never use _ attributes, they are meant to be private.

Use the non underscored versions for more plugin compatibility...

By the way, if you want to get the mouse's coordinates because this doesn't add an onmousemove event, you can't do it without a bir of code...

So you'll have to do something like this:

  var mouseX;  var mouseY;(function () { // must protect from pollution  function _onMouseMove(event) {    mouseX = Graphics.pageToCanvasX(event.pageX);    mouseY = Graphics.pageToCanvasY(event.pageY);  };  function _onTouchMove(event) {    for (var i = 0; i < event.changedTouches.length; i++) {      var touch = event.changedTouches;      mouseX = Graphics.pageToCanvasX(touch.pageX);      mouseY = Graphics.pageToCanvasY(touch.pageY);    }  };  document.addEventListener('mousemove', _onMouseMove);  document.addEventListener('touchmove', _onTouchMove);})();And then use mouseX and mouseY as you need...

Remember to hide all that code inside something like a module or anonimous function because it will fill the global space with variables if not...
I've moved this thread to Javascript/Plugin Support. Please be sure to post your threads in the correct forum next time. Thank you.
Please, never use _ attributes, they are meant to be private.

Use the non underscored versions for more plugin compatibility...

By the way, if you want to get the mouse's coordinates because this doesn't add an onmousemove event, you can't do it without a bir of code...

So you'll have to do something like this:

  var mouseX;  var mouseY;(function () { // must protect from pollution  function _onMouseMove(event) {    mouseX = Graphics.pageToCanvasX(event.pageX);    mouseY = Graphics.pageToCanvasY(event.pageY);  };  function _onTouchMove(event) {    for (var i = 0; i < event.changedTouches.length; i++) {      var touch = event.changedTouches;      mouseX = Graphics.pageToCanvasX(touch.pageX);      mouseY = Graphics.pageToCanvasY(touch.pageY);    }  };  document.addEventListener('mousemove', _onMouseMove);  document.addEventListener('touchmove', _onTouchMove);})();And then use mouseX and mouseY as you need...

Remember to hide all that code inside something like a module or anonimous function because it will fill the global space with variables if not...


Thanks for your answer!

Well, I was a heavy RPG maker 2003 user and I'm quite good at eventing, but my scripting and programing skill are very very low. So I have 4 questions:

1)I don't understand what do you mean with the underscored notetags, why are they private?

2) Where can I learn more about notetags?

3) How do I hide the code in a module or anonimous function? What does it mean that it will fill the global space with variables?

4) How do I use the code you just provided me? I should put it on a .txt file and rename it to js and use it as a plugin?

Sorry for my basic questions, thanks for your answers 🙂
1)

No, notetags no, attributes:

I was meaning than you may use

TouchInput.x and not

TouchInput._xUsing things with '_' before the name is not a good thing to do, they are meant for private use, think of those variables as ruby's @x, they are used to work inside the object, but not from the outside.

Keep in mind It's just a convention, not something than it's really private. 

An attribute is a variable attached to an object,

in other words: TouchInput._x is the '_x' attribute of TouchInput.

All javascript objects have the ability (except numbers, strings, null, and booleans) to add any new property you need.

So you can think any javascript object as a table with one entry being keys and the other value.

2)

Notetags, is a way scripters decided to use for adding functionality and configuration to database objects, and are a whole new topic and you may want to post it in another thread.

3) 

This is an anonymous function:

(function () {// your code should be inside this})();This basically means, I created a function than executes after being created, so anything runs inside and never gets out (unless you make it explicitly global)

"Filling your global space with names" means you are adding a lot of attributes to the window class.

Any variable  you create in javascript code (unless they are inside a function) and it's the best to keep that as small as possible, because some other person may use the same name and may crash both plugins/scripts. 

So in other works, I think you may want to do this.

Create a new file called "Mouse.js" or use any name you need.

Copy this:

// Let's create a point because it looks nicervar Mouse = new Point();// this stats an anonimous function(function () { // must protect from pollution  function _onMouseMove(event) {    Mouse.x = Graphics.pageToCanvasX(event.pageX);    Mouse.y = Graphics.pageToCanvasY(event.pageY);  };  function _onTouchMove(event) {    for (var i = 0; i < event.changedTouches.length; i++) {      var touch = event.changedTouches;      Mouse.x = Graphics.pageToCanvasX(touch.pageX);      Mouse.y = Graphics.pageToCanvasY(touch.pageY);    }  };  document.addEventListener('mousemove', _onMouseMove);  document.addEventListener('touchmove', _onTouchMove);})();Put it in your js/plugins folder

Open MV, add it as a plugin

And then everywhere you need it you just do:

Mouse.x // to get xMouse.y // to get yif you want to keep using mouseX and mouseY (because that are the only real difference between this and that code)

follow the same steps, as before.
 
Wow, Ramiro, thank you very much!  That helps me a lot


May I abuse from your kindness and knowledge with this questions?:


I'm trying to do a custom menu (I'm placing images on the screen that should be clickable), and I Need:


            1) Save mouse coords in variables (done) (thanks to the code you provided me, thanks!)


            2)  I'm setting events with conditional branches for the area that represents the "clickable object",is working good so far, but I wonder if exists any simpler way of doing this, this is my event window:

Spoiler
event_zpsbigday0f.jpg
3) I need to find a way to create a conditional branch for when the left mouse button is clicked, but I'm not getting it right. This is what I have:

Spoiler
event2_zpsrb0rvxc3.jpg
4) Eventually I will want to make it a custom battle, where the mouse use is independant of player move, so I need to disable the "move to mouse click" but preserving the ability to move with the arrow keys. How can I do that?


I can't thank you enough for your help
Please as I told you before.

You may want to separate this question one per thread, so other people looking for the same thing can look at your post.

If you want an alternative to reduce the amount of code do this:

Create a common event (open the database and go to common events)

Call it something like: "mouse rect checker"

add something like this (this are all events):

switch [ Over rect ] = offif variable [ Start X ] <= variable [ Mouse X ]    if variable [ Start Y ] <= variable [ Mouse Y ]      if variable [ End X ] >= variable [ Mouse X ]        if variable [ End Y ] >= variable [ Mouse Y ]          switch[ Over rect ] = on        end      end    endendThen before calling this common event do this in your menu:

variable[ Start X ] = (put a value here)

variable[ End X ] = (put a value here)

variable[ Start Y ] = (put a value here)

variable[ End Y ] = (put a value here)

call common event: Check rect

Now you can check if the switch [ Over rect ] is on or off, if the switch is on, you are over the rect, if the switch is off, you weren't over the rect.

This is the probably "modular" way to do that with eventing.

There is a short way of course, using scripts...

if you want to check over a rect and want to avoid all that eventing, just reeplace your mouse plugin with this newer one:

// Let's create a point because it looks nicervar Mouse = new Point();Mouse.isOverRect = function (x, y, width, height) {

  return (this.x >= x) && (this.y >= y) && (this.x <= x + width) && (this.y <= y + height);

}

// this stats an anonimous function (function () { // must protect from pollution   function _onMouseMove(event) {     Mouse.x = Graphics.pageToCanvasX(event.pageX);     Mouse.y = Graphics.pageToCanvasY(event.pageY);   };   function _onTouchMove(event) {     for (var i = 0; i < event.changedTouches.length; i++) {       var touch = event.changedTouches;       Mouse.x = Graphics.pageToCanvasX(touch.pageX);       Mouse.y = Graphics.pageToCanvasY(touch.pageY);     }   };   document.addEventListener('mousemove', _onMouseMove);   document.addEventListener('touchmove', _onTouchMove); })();

And then as an if condition in your event you can call the function:

Mouse.isOverRect(x, y, width, height)As something like this as a script call condition (last condition available on the last page if I remember right):

if script call: [ Mouse.isOverRect(0, 0, 32, 32) ]   > continue eventingendthis will check if the mouse is over a rect starting from the top left corner at (0, 0) with a width and height of 32 pixels.
Thank you x1000!!!! I consider this issue solved, if I have other questions I will make another topic, you are my hero! 🙂

Original thread: https://forums.rpgmakerweb.com/threads/mouse-notetags.48191/