How to access other plugin's variables?

I'm trying to write a patch to make two plugins talk to each other.


The first begins with this:


(function(_) {

"use strict";

_.fileWidth = _.width * 3;
_.fileHeight = _.height * 4;




In the second, I need to access the fileWidth and fileHeight values above.  I've used:


var bitmap = new Bitmap(_.fileWidth, _.fileHeight);




but when I run, I get an error:


ReferenceError


_ is not defined


I could load parameters from one plugin into another and recalculate the values, but I'm hoping there's a more direct way.
That is because you are referencing the variables incorrectly I think.


At the end of your first piece of code there should be something like this })(something). So I believe it should be something like the following:

Code:
var bitmap = new Bitmap(something.fileWidth, something.fileHeight);
That's perfect!  Thanks so much 🙂
Yes, and to clarify why, the "_" is just an alias. Another commonly used one is "$". The way it's setup, all the code is inside an anonymous function that's called when the script is being parsed, and for some plugins a class may be passed to the function as it is often referenced/added to/modified. It's just like any other function argument, however, so if you want to get access to values assigned to something aliased that way, you need to know what that object is. 
This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-access-other-plugins-variables.71811/