MV Datamanager save/extract not working for non-length/no-index array

Why won't this properly save the array called BISH.respawnEvents?
Logging the value during save returns the correct information:
1637707317799.png

1637707287169.png


Upon extracting, it logs:
1637707342056.png


Is it that the array is not indexed with integers? It's the only thing I can think of. Or is there another reason?

JavaScript:
//Saving contents
BISH.DataManager_makeSaveContents = DataManager.makeSaveContents;
DataManager.makeSaveContents = function() {
    var contents = BISH.DataManager_makeSaveContents.call(this);
 
    var difficulty = {};
    difficulty._heroDamage = Difficulty._heroDamage;
    difficulty._enemyDamage = Difficulty._enemyDamage;
    contents.bishEvents = BISH.respawnEvents;
    console.log(contents.bishEvents);
    contents.difficulty = difficulty;
    return contents;
};

BISH.DataManager_extractSaveContents = DataManager.extractSaveContents;
DataManager.extractSaveContents = function(contents) {
    BISH.DataManager_extractSaveContents.call(this, contents);
 
    BISH.respawnEvents = contents.bishEvents;
    var difficulty = contents.difficulty;
    Difficulty.setDifficulty(difficulty._heroDamage, difficulty._enemyDamage);
};

JavaScript:
BISH.respawnEvents = [];

    BISH.setLastKilledEventEnemy = function(killedEvent) {
        var mapEventString = BISH.getMapEventString(killedEvent);
        var deathDate = new Date;
        BISH.respawnEvents[mapEventString] = {};
        killedEvent = BISH.respawnEvents[mapEventString];
        killedEvent.deathDate = deathDate.getTime();
        killedEvent.respawnDate = false;
    };

    BISH.getMapEventString = function(mapEvent) {
        return mapEvent._mapId + ", " + mapEvent._eventId;
    };

    Game_Event.prototype.eventRespawn = function (minutes) {
        minutes = minutes || 15; //Base time is 15 minutes.
        var time = minutes * 60 * 1000; //Convert time into milliseconds.
        var compareDate = new Date;
  
        mapEvent = BISH.respawnEvents[BISH.getMapEventString(this)];
  
        if (mapEvent.respawnDate == false) mapEvent.respawnDate = mapEvent.deathDate + time;
  
        compareDate = mapEvent.respawnDate - compareDate.getTime();
        //console.log("Respawn in: " + (compareDate / 1000 / 60).toFixed(0));
        if (compareDate <= 0) return true;
    };

Is it because it is an object?
JavaScript:
Line 6: BISH.respawnEvents[mapEventString] = {};

Regardless of the cause, can I somehow save the array and its contents?
And can someone tell me what an array that doesn't have index numbers is called?

Best regards,
Bishiba

EDIT:
Did a test by doing:
1637709008214.png

And the extract log gave me:
1637709027579.png

So it seems that the issue lies with the integers.

So... My alternative, that I can come up with, given my current experience is that instead of using a string "x, y" I can use z = Math.round("x" + "y"). This will give me an integer. However. The integer might get a value of upwards to 500000. And, I am relatively sure that having an array of that size that only utilizes maybe 1-2% of the size is rather pointless. But at least it works, however, before I do that, does anyone have another idea? 🙂
1637714409598.png

This only reaches 10000, but that's because the mapId is 104 and the eventId is 46, if the eventId was also above 100, then it would be 100000. But, perhaps there is no downside to having a big array as long as the contents are null?
Array properties with non-integer identifiers are not included by the standard array iterator, therefore get skipped by JSON.stringify. More info here:
I would advise against large/sparse arrays here because JSON.stringify converts empty slots to null, e.g. JSON.stringify(new Array(10000)) is 50001 characters long.

If you want to have non-integer indices, use an object {} instead of an array []. Arrays are objects optimised for use with integer indices.
Array properties with non-integer identifiers are not included by the standard array iterator, therefore get skipped by JSON.stringify. More info here:
I would advise against large/sparse arrays here because JSON.stringify converts empty slots to null, e.g. JSON.stringify(new Array(10000)) is 50001 characters long.

If you want to have non-integer indices, use an object {} instead of an array []. Arrays are objects optimised for use with integer indices.
Yeah. I also realized that my new idea has the issue where x = 1, y = 23 is the same as x = 12, y = 3.

Ah well, it is good to know at least. Also, since the actual respawn function is rather simple, it shouldn't be much of an issue to change how it operates to make it compatible with the save.

I am loving that this evening was the first time I realized my variables aren't saving 😛

Original thread: https://forums.rpgmakerweb.com/threads/datamanager-save-extract-not-working-for-non-length-no-index-array.142414/