Problems with Arrays

I'm having a really hard time dealing with arrays in RMMV.

If I create an event and use a script inside like this:

var ar = [];ar[0] = "example";Then I can use the array value during only this event. The array will not persist through the gameplay or other events. If I try to use the value ar[0] in any other event, the game crashes with: "ar is not defined".

I also tried to include the script to create the array in a common event or start up event, but they don't persist in the game, it's like they are not global variables.

My project will need to use multi-dimensional arrays, but I can't make a simple one to work, outside the same event.

How can I create persistent arrays, or global variables to use anywhere in the game? Is there a way inside script calls or do I have to use a plugin to control the global variables?

Please, assume that I don't want to work with the "gameVariables", unless it can somewhat accept multi-dimensional objects/arrays inside it.
I think they create a Block Scope for the Script Event with its own Scope:

var a = 2;(function(){ var a = 3; console.log( a ); // 3})();console.log( a ); // 2You can add the Variable to a global object like "DataManager":

DataManager.ar = [] ....
I think they create a Block Scope for the Script Event with its own Scope:

var a = 2;(function(){ var a = 3; console.log( a ); // 3})();console.log( a ); // 2You can add the Variable to a global object like "DataManager":

DataManager.ar = [] ....
Wow, this works perfectly. Thanks so much!!!

I wanted to give you a million likes, but I can only give one...
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/problems-with-arrays.47239/