Global Variable Question

Rink27

Veteran
Veteran
Joined
Jul 18, 2014
Messages
222
Reaction score
13
First Language
English
Primarily Uses
RMMV
Sorry for the necro, but if I create my own global variable with a unique name that I'd only place in two scripts, it should be safe right?

It is only defined in one of the two scripts and its value is used (not changed) in both of the two scripts. As long as no other script calls for a variable with that unique name and changes the value, it should be safe, right?
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,440
First Language
French
Primarily Uses
RMMV
Simply remove VAR before the declaration.
But the problem is global will not save.
But a bether solution is create a new objet at boot game.
They will save in manager

Code:
// At BOOT GAME LOAD ALL GLOABAL VARIABLE
alias_AllMyGlobal_initialize = DataManager.setupNewGame;
DataManager.setupNewGame = function() {
    alias_AllMyGlobal_initialize.call(this);
    $gameVariables.Global = new Global();
};

function Global() {
this.myglobal1 = null;
this.myglobal2 = 4;
this.myglobal3 = [4,4,8];
this.myglobal4 = function(){};
}

//change your valur very easy anywhere
$gameVariables.Global.myglobal2 = [10,'hello',[1,2]];
 

mlogan

Global Moderators
Global Mod
Joined
Mar 18, 2012
Messages
15,377
Reaction score
8,536
First Language
English
Primarily Uses
RMMV
@Rink27

I've split your topic into a new one. Please refrain from necroposting in the future.

 

Rink27

Veteran
Veteran
Joined
Jul 18, 2014
Messages
222
Reaction score
13
First Language
English
Primarily Uses
RMMV
Simply remove VAR before the declaration.
But the problem is global will not save.
But a bether solution is create a new objet at boot game.
They will save in manager

Code:
// At BOOT GAME LOAD ALL GLOABAL VARIABLE
alias_AllMyGlobal_initialize = DataManager.setupNewGame;
DataManager.setupNewGame = function() {
    alias_AllMyGlobal_initialize.call(this);
    $gameVariables.Global = new Global();
};

function Global() {
this.myglobal1 = null;
this.myglobal2 = 4;
this.myglobal3 = [4,4,8];
this.myglobal4 = function(){};
}

//change your valur very easy anywhere
$gameVariables.Global.myglobal2 = [10,'hello',[1,2]];
Thank you. Actually, there's something fundamental I don't fully understand (hence me looking at global variables).

Code:
    Window_ZenInfo.prototype.windowHeight = function() {
        return Scene_Menu.prototype._commandWindow.height;
    };
The above doesn't work since height isn't defined. It is though, in a function above. How do I get it to reference to a value elsewhere in the same plugin? Also, what is the method to refer to a value from another plugin?

Of if I want to reference a variable such as the height, is it best to create a single function that returns that value and call that function whenever?
 

Rink27

Veteran
Veteran
Joined
Jul 18, 2014
Messages
222
Reaction score
13
First Language
English
Primarily Uses
RMMV
Simply remove VAR before the declaration.
But the problem is global will not save.
But a bether solution is create a new objet at boot game.
They will save in manager

Code:
// At BOOT GAME LOAD ALL GLOABAL VARIABLE
alias_AllMyGlobal_initialize = DataManager.setupNewGame;
DataManager.setupNewGame = function() {
    alias_AllMyGlobal_initialize.call(this);
    $gameVariables.Global = new Global();
};

function Global() {
this.myglobal1 = null;
this.myglobal2 = 4;
this.myglobal3 = [4,4,8];
this.myglobal4 = function(){};
}

//change your valur very easy anywhere
$gameVariables.Global.myglobal2 = [10,'hello',[1,2]];
If I do, say x: $gameVariables.Global.myglobal2,

The x isn't updated with the value of myglobal2.
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,440
First Language
French
Primarily Uses
RMMV
If I do, say x: $gameVariables.Global.myglobal2,
What ?
you mean
Code:
var x = $gameVariables.Global.myglobal2
declare like thats
var x = null; // is for function scope
x = null; // is global, you can use very anywhere in game or in a plugin , but will not save
 
Last edited:

mogwai

1984
Veteran
Joined
Jun 10, 2014
Messages
875
Reaction score
591
First Language
English
Primarily Uses
RMMV
$gameVariables.value is already global and it will save with the game.
What I would do, if the variable needs a string value is key it to a global array.

For example.
PHP:
// a plugin with some strings for the game variables
var gameVarOneStrings = ["undefined","hello","I'm a game variable string","I'm also a string"];
                       // [0,1,2,3,...]
// then to get the string value
var key = $gameVariables.value(1);
var string = gameVarOneStrings[key];
EDIT: Also, correct me if I'm mistaken, but if var is used inside a function, it's still function scope. It will still get the function var if there is a function var inside. A fundamental way to remember global scope is window.variable to not get it mixed up or simply don't use function scope variables of the same name. I'm big on window.someVariable, because my Greasemonkey scripts won't reach outside of their wrapper without it.
 
Last edited:

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

Latest Threads

Latest Profile Posts

Day 9 of giveaways! 8 prizes today :D
He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.

Forum statistics

Threads
106,040
Messages
1,018,476
Members
137,824
Latest member
dobratemporal
Top