(Scripting) Need help saving map to file

I’m working with a map that uses 2 tilesets but to import to Construct I need 2 separate maps each using 1 tileset

So I decided to make a script that splits the map into 2 maps. But I’m not understanding how to save the new map

let path = tiled.promptSaveFile(dir, "Tiled map files (*.tmx)");
let format = tiled.mapFormatForFile(path);
tiled.log(newMapA.save());

The prompt shows up and I pick a file name, but it just saves over the original map’s file. The log message prints “true”

You’re 80% of the way there: you got the format to use, but you’re not using it. You can use the format to write the file with format.write(map, path).

map.save() is just the same as using File > Save, and you should not be using it in custom export format.

1 Like

Thank you for the quick reply, it worked perfectly

Just one additional note I’d make, is that when you already know you want to save the map as tmx, then you should probably just use tiled.mapFormat("tmx") instead of mapFormatForFile.