MZ Change tiles in javascript

Sometimes I may like to manipulate the map in complicated ways using events. One way to do this is to lay down many other events in the map and have them trigger with a variable. This gets cumbersome when I want to manipulate many tiles. So I was curious if there is a way to do this in javascript.

Here's what I got,

To change a tile in javascript, I am coding like this:

$dataMap.data[670] = 874;
$gameMap.refresh()

where xxx is the tile location. Tile locations and tiles appear to be numbered according to the rules in this thread: https://forums.rpgmakerweb.com/index.php?threads/how-to-determine-your-tileid.91129/#post-827144

However, when I do this, and open and close the game menu, this is undone. This is a well-known issue in this area (https://steamcommunity.com/app/363890/discussions/4/2650805212049402002/, https://forums.rpgmakerweb.com/inde...opy-tiles-and-change-tiles.90437/#post-843176).

A workaround I've tried is to create a parallel event that checks on every one frame if (e.g.) $dataMap.data[670] is back to its original, and if so, it triggers the above lines of script again. This is probably a little inefficient, but it's probably not a big deal since checking a number every frame shouldn't be too big of a deal. The problem with this approach is that there is a delay between closing the game menu and the map refreshing, which just looks awful (and maybe could create bugs down the line if I use this for more complicated things).

So, two questions:

(1) Is there a better way to change map tiles in the current map using javascript? (Assume that I want to change map tiles to tiles in the same tileset.) I read that for rpg maker MV, plugins have used $gameSystem.saveMapTile and $gameSystem.restoreMapTiles to save and restore the map state into the current save file (see e.g. https://forums.rpgmakerweb.com/inde...opy-tiles-and-change-tiles.90437/#post-843176). However, in rpg maker MZ, $gameSystem.saveMapTile doesn't seem to be exposed to the user (it gives me "not a function" when I try to call it, at least).

(2) If there isn't, is there a way to call a Wait event (maybe a temporary black screen?) when the player closes the game menu, so as to delay a bit so that the game has time to call the parallel event I described above?

Thanks in advance for any help! I hope through this question I can also learn a bit more about using javascript in rpg maker mz 🙂 .
I read that for rpg maker MV, plugins have used $gameSystem.saveMapTile and $gameSystem.restoreMapTiles to save and restore the map state into the current save file (see e.g. https://forums.rpgmakerweb.com/inde...opy-tiles-and-change-tiles.90437/#post-843176). However, in rpg maker MZ, $gameSystem.saveMapTile doesn't seem to be exposed to the user (it gives me "not a function" when I try to call it, at least).

It never was a function. It would have only been added by the plugin.

Moved to: Plugin Requests

Have you tried my copy/paste tiles plugin for MV? I think I read somewhere that it works in MZ with Fossil.
I've seen a paid plugin, Drag Sandbox Map for MZ on itch.io for 'city building' - placing/replacing tiles etc. I was looking at getting it for something I want to add to one of the game ideas with which I'm experimenting.

It may have some of the functionality you are after (or at least offer something to model off.) They do have a demo download on the itch page but I haven't checked to see if it's obfuscated.
notRitter also did a plugin for changing tiles.

Original thread: https://forums.rpgmakerweb.com/threads/change-tiles-in-javascript.143523/