How to access other plugin's variables?

Status
Not open for further replies.

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,111
Reaction score
13,714
First Language
English
Primarily Uses
RMMV
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.
 

Sarlecc

Veteran
Veteran
Joined
Sep 16, 2012
Messages
453
Reaction score
211
First Language
English
Primarily Uses
RMMV
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);
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,111
Reaction score
13,714
First Language
English
Primarily Uses
RMMV
That's perfect!  Thanks so much :)
 

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
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. 
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,713
First Language
English
Primarily Uses
RMVXA
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.
 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Don't forget, aspiring writers: Personality isn't what your characters do, it is WHY they do it.
Hello! I would like to know if there are any pluggings or any way to customize how battles look?
I was thinking that when you start the battle for it to appear the eyes of your characters and opponents sorta like Ace Attorney.
Sadly I don't know how that would be possible so I would be needing help! If you can help me in any way I would really apreciate it!
The biggest debate we need to complete on which is better, Waffles or Pancakes?
rux
How is it going? :D
Day 9 of giveaways! 8 prizes today :D

Forum statistics

Threads
106,049
Messages
1,018,547
Members
137,835
Latest member
yetisteven
Top