How does the $gameMap.data array work?

I know the algorithm to 'unflatten' the 1d array into a 2d + z-index:

var tileIndex = (z * section.height + y) * section.width + x;However, when using this:

Spoiler
$dataMap.data = section.data; // section.data contains the data from another map that I'm trying to paste into the current map, overwriting the old data$gameMap.setup($gameMap._mapId);Result: Nothing happens. I actually expected this solution to work.
 
Attempt 2:
Spoiler
for(var i=0; i<section.data.length; i++)    {        $dataMap.data = section.data;    }$gameMap.setup($gameMap._mapId);Result:

So something is wrong regarding the x & y locations... But how is this code different compared to $dataMap.data = section.data; (if the maps are of equal size)... How can the result be different?

 
Attempt 3:
Spoiler
var z = 1; for(var y=0; y<section.height; y++) { for(var x=0; x<section.width; x++) { var index = (z * section.height + y) * section.width + x; $dataMap.data[index] = section.data[index]; } }$gameMap.setup($gameMap._mapId); Result: Nothing happens.
 
Attempt 3a (same result as attempt #2):
Spoiler
    var z = 0; // <<<<<<<<<<<<<<<<<<<<< z is zero now.    for(var y=0; y<section.height; y++)    {        for(var x=0; x<section.width; x++)        {            var index = (z * section.height + y) * section.width + x;            $dataMap.data[index] = section.data[index];        }}$gameMap.setup($gameMap._mapId);    Result:
 
Attempt 4:
Spoiler
$dataMap.data = [];$gameMap.setup($gameMap._mapId);Result: Nothing happens. So it seems the tiles are not refreshed just by calling the setup? Or atleast not properly because the old ones are still showing.
 
I do not understand what I'm doing wrong.
By looking at in the console it seems to be an array of data information pertaining to the map its self, so i guess information about the map.

So:

return $dataMap.data[(z * height + y) * width + x] || 0;Looks like it calculates information about the specific tile at that specific location.
Sorry I don't understand, how does that answer my question? How can I use that info (that I already had) to use the map data from another map for the current map?

Solution:

I found the problem. I had to resize the current map first before loading that data of course...

Still don't know why attempt 1 and 2 are different though.
Why would you want to use this info?
Sorry I don't understand, how does that answer my question? How can I use that info (that I already had) to use the map data from another map for the current map?

Solution:

I found the problem. I had to resize the current map first before loading that data of course...

Still don't know why attempt 1 and 2 are different though.
I also work with map data. and it won't work if you're not transfering to same map to reload the map graphic... ( i try many ways and the only thing work is that)

but there's also asynch loading problem that sometime could cause $dataMap null error when playing it via browser.

in summary working with map data is really pain in the @ss.
I don't have to transfer to the same map for it to work. It just works.

My guess is that you forgot to wait for the map-data to load. You MUST use the callbacks when loading map-data to determine when they are done and THEN you copy the map-data, never before!
i use callback. but somehow it doesn't change. 😀 . maybe i do some mistake somewhere though 😀 .

Original thread: https://forums.rpgmakerweb.com/threads/how-does-the-gamemap-data-array-work.52141/