2
\$\begingroup\$

I'm coming from C++, diving into JS and enjoying the journey so far but I've been at an en passe for the past 2 days and I'm exhausted.

I need help figuring out how to access variables across plugins.

I tried following the guidance in this posting (and numerous others stating to follow the same syntax): https://forums.rpgmakerweb.com/index.php?threads/mv-syntax-for-variables-in-script-calls.48422/

I set these values in plugin1.js:

var weaponRight = 0; 
var weaponHeight = 0;

var a = weaponRight;
var b = weaponHeight;

$gameVariables.setValue(5, a);
$gameVariables.setValue(6, b);

Then try to access them in this script:

var z1 = eval($gameVariables[5]);
var z2 = eval($gameVariables[6]);
...
this.x += (z1 || 0);
...

if I just enter an int, say 5--in place of z1--the transform executes. In addition, I emulated the parsing logic in the first JS file to the 't', so I'm certain the error is coming from my ignorance.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

So, I figured it out. I ended up just using a global variable, ensuring that I defined it outside the scope of any function so its value would not be cleared when that function went out of scope.

var globalDummyVariable = 0;

Then I just made a call directly in the scope of another function like this:

Yanfly.globalDummyVariable

This is the quick and dirty way to get it up and running, but I think it's a bit safer for new programmers to get a handle on instead of using the new keyword and not deleting objects.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .