How to use array in another method ?

Hello,

I created and array here :

(function() {var layers = [];Next I use it like this :

Spriteset_Map.prototype.createLayers = function() {var layer = this.layers.push(new Sprite());

And finally, the problem appear here :

Spriteset_Map.prototype.updateLayers = function() { var lel = this.layers.length;};I got : Cannot read property 'length' of undefined

What is happening ? And how to solve it ?

Thanks for help !
you use var inside of a function a var inside of a fonctionn limit is use

although you use it inside of a anaonymous function are you sure you are using it properly?
"this" in this case points to the Spriteset_Map instance, while "layers" belongs to the anonymous function. Just leave out the "var " in front of it.
Thanks it's solved ! 😀

Original thread: https://forums.rpgmakerweb.com/threads/how-to-use-array-in-another-method.54531/