javascript - variable keeps getting updated without any code that says to -


i have 2 variables in sandbox based game.

blocks 

(array)

and

blockssave 

(also array)

but have these functions:

var game = {     blocksave: function() {         blockssave = blocks;         blockserasedsave = blockserased;     },     blockload: function() {         blocks = blockssave;         blockserased = blockserasedsave;     },     blockreset: function() {         blocks = [];         blockserased = 0;     } } 

if call blocksave once, keeps getting saved until reset if save keep building load, loaded world after saved , builded more. if reset, though, stops saving until game.blockload(). tried functions being defined inside button onclick.

i have looked through code , save function called when button pressed. (i tested that)

the clue function being called on , on run game. (save not inside it)

blockssave = blocks not copy array. points blockssave reference same blocks array.

if elements of array primitives, can make shallow copy of blocks array this:

blockssave = blocks.slice(0);

if elements objects, need deep copy array looping on , making new object each element.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -