Global Variable Question

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?
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]];
@Rink27

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

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?
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.
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
$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.

Original thread: https://forums.rpgmakerweb.com/threads/global-variable-question.75140/