Load a map which wasn't bundled with the game?

I'm trying to make a system where the server uploads its custom map to the client, which will load it as soon as possible.

The upload part works, but when I replace Map005.json(and MapInfos.json) with the new files, the game throws the error "Cannot read property 'scrollType' of null". Trying to load a map not listed in the database(lets say, Map006.json) throws the same error. Not replacing MapInfos.json throws the same error too.

Image:
sem_tz15.png


The files are fine, as I tested manually loading them by closing the game, changing the files to then open, and it worked. But I need a system that doesn't require the game to be closed.

My code for replacing the files is simply this:
Code:
fs.copyFileSync('./www/temp/Map005.json', './www/data/Map005.json')
fs.copyFileSync('./www/temp/MapInfos.json', './www/data/MapInfos.json')
$gamePlayer.reserveTransfer(5,5,5,2,2);
$gameTemp.reserveCommonEvent(6)


So, how do I load a new map, which was not bundled with the game, without closing it?
does the mapinfos file contain the correct data for including the new map?

There are two things that could have gone wrong here - first is that the data in the new mapinfos file is wrong and does not contain the required data, and the other possibility is a problem with server permissions preventing the upload.

I suggest you make the following test: upload the current project with all its maps as it is now, test it to work correctly.
then make a new map in that same project, and try to upload that with your methods.

If that fails it's most likely a server issue, if that works then the data in the files from the other try was wrong.
does the mapinfos file contain the correct data for including the new map?

There are two things that could have gone wrong here - first is that the data in the new mapinfos file is wrong and does not contain the required data, and the other possibility is a problem with server permissions preventing the upload.

I suggest you make the following test: upload the current project with all its maps as it is now, test it to work correctly.
then make a new map in that same project, and try to upload that with your methods.

If that fails it's most likely a server issue, if that works then the data in the files from the other try was wrong.
The upload part works, I've tested it. Also, the mapInfos.json should be fine, as manually closing, replacing files to then load it works.

After a few more (hundred) tests, I believe the problem is either MV is not having time to update its info, or "fs.copyFileSync" is actually not being sync, because when removing the lines "$gamePlayer.reserveTransfer(5,5,5,2,2);" and "$gameTemp.reserveCommonEvent(6)", it throws no error, and If I wait the files to be copied and changed before running those lines in the chromium dev tool, it works.

Anyone knows what is happening?


EDIT: Actually, would anyone know another method to load maps not bundled? Like in a DLC way, i don't know. I honestly give up of that system of replacing files, it bugs EVERYTHING
I'm not well versed in server coding, but it could be because of $dataMapInfo. RPG Maker is weird because although you can update a map in the middle of the game (change the map data, update the Scene_Map) and it would be fine, it only loads everything in the data files ($dataActors, $dataClasses, etc.), including $dataMapInfo, only once when you open the game. Perhaps your sync happens after the initial data loading, so it's reading the correct map data but the old mapInfo. Just my uneducated guess.
I'm not well versed in server coding, but it could be because of $dataMapInfo. RPG Maker is weird because although you can update a map in the middle of the game (change the map data, update the Scene_Map) and it would be fine, it only loads everything in the data files ($dataActors, $dataClasses, etc.), including $dataMapInfo, only once when you open the game. Perhaps your sync happens after the initial data loading, so it's reading the correct map data but the old mapInfo. Just my uneducated guess.
Actually it seems to sync, but takes some time to do so, in a async way. Anyway, seems that replacing files isn't a good idea(it causes too many bugs)


Anyone has ideas on how could I implement this in another way?

EDIT: Maybe if I copy the $gameMap and $dataMap objects from the server and send to the client, it could work. But how can I re-render the map with the new info after transfering to it?
quite late to do this but: UP.

I tried my idea of copying $gameMap and $dataMap but it also didn't work.

EDIT:

FINALLY got it working! After more research, I've noticed that a few config files are actually loaded when the game is loaded(files like mapInfo.json and Tilesets.json). All I had to do was read the new ones and push the new information to the objects that store them($dataTilesets, $dataMapInfos,etc)
Thread closed IgnoreMe

Original thread: https://forums.rpgmakerweb.com/threads/load-a-map-which-wasnt-bundled-with-the-game.107669/