Page 1 of 1

[Solved]Help required - Usage of parse_map_exchange_string(map_exchange_string)

Posted: Wed Feb 05, 2020 1:32 am
by Squelch
Hi all,

I would like to dump the map settings that I have found to work well for me from several existing saves, and then create them as presets.

I have tried to write map_gen_settings and map_settings to files and expected something like map_gen_presets.lua However, while I do get a partial output from

Code: Select all

/c game.write_file("map-gen-settings.txt", serpent.block(game.surfaces[1].map_gen_settings))

Attempting similar with map_settings to retrieve the difficulty and enemy settings etc, I simply get:

Code: Select all

{__self = "userdata"}
My understanding is that I must iterate userdata, or interrogate specific values which would then require further formatting to satisfy the presets lua.

I then found parse_map_exchange_string(map_exchange_string) which was introduced in 17.50, and would appear to give exactly what I need in the returned MapExchangeStringData

Sadly, I've not been able to get this to work.
Using default settings on a new map and exporting the map string, I have tried this:

Code: Select all

/c game.write_file("my-map-settings.txt", parse_map_exchange_string(>>>eNpjYBBiYGYAgwZ7EOZgSc5PzIHxQJgrOb+gILVIN78oFVmYM 7moNCVVNz8TVXFqXmpupW5SYjGKYo7Movw8dBNYi0vy81BFSopSU 4uRRbhLixLzMktz0fUyMH6/sbyxoUWOAYT/1zMo/P8PwkDWA6BfQ JiBsQGiEigGA6zJOZlpaQwMCo5A7ASSZmRkrBZZ5/6waoo9I0SNn gOU8QEqciAJJuIJY/g54JRSgTFMkMwxBoPPSAyIpSVAK6CqOBwQD IhkC0iSkbH37dYF349dsGP8s/LjJd+kBHtGQ1eRdx+M1tkBJdlB/ mSCE7NmgsBOmFcYYGY+sIdK3bRnPHsGBN7YM7KCdIiACAcLIHHAm 5mBUYAPyFrQAyQUZBhgTrODGSPiwJgGBt9gPnkMY1y2R/cHMCBsQ IbLgYgTIAJsIdxljBCmQ78Do4M8TFYSoQSo34gB2Q0pCB+ehFl7G Ml+NIdgRgSyP9BEVBywRAMXyMIUOPGCGe4aYHheYIfxHOY7MILzE EjVF6AYIzPMkzCjILSAAzMDAgCTxWTGtfUAK4Wh8A==<<<))
This results in an error:

Code: Select all

Cannot execute command.Error:(command):1:unexpected symbol near '>'
Ok, it looks like the syntax is incorrect, so I tried encapsulating the map string in quotes " ". That gives me a "nil" return.

Has anyone had any success with this command? I would be very grateful for mistakes to be pointed out.

Re: Help required - Usage of parse_map_exchange_string(map_exchange_string)

Posted: Wed Feb 05, 2020 2:40 pm
by Squelch
I've now scoured as many mods as I could find that look like they might use this command for a working example, including a sitewide search of GitHub, all without success. I'm beginning to wonder if it is actually bugged.

If someone has knowledge of this command working properly, I would be grateful for some pointers. Thanks.

Re: Help required - Usage of parse_map_exchange_string(map_exchange_string)

Posted: Wed Feb 05, 2020 2:56 pm
by Bilka
Squelch wrote:
Wed Feb 05, 2020 1:32 am
Using default settings on a new map and exporting the map string, I have tried this:

Code: Select all

/c game.write_file("my-map-settings.txt", parse_map_exchange_string(>>>eNpjYBBiYGYAgwZ7EOZgSc5PzIHxQJgrOb+gILVIN78oFVmYM 7moNCVVNz8TVXFqXmpupW5SYjGKYo7Movw8dBNYi0vy81BFSopSU 4uRRbhLixLzMktz0fUyMH6/sbyxoUWOAYT/1zMo/P8PwkDWA6BfQ JiBsQGiEigGA6zJOZlpaQwMCo5A7ASSZmRkrBZZ5/6waoo9I0SNn gOU8QEqciAJJuIJY/g54JRSgTFMkMwxBoPPSAyIpSVAK6CqOBwQD IhkC0iSkbH37dYF349dsGP8s/LjJd+kBHtGQ1eRdx+M1tkBJdlB/ mSCE7NmgsBOmFcYYGY+sIdK3bRnPHsGBN7YM7KCdIiACAcLIHHAm 5mBUYAPyFrQAyQUZBhgTrODGSPiwJgGBt9gPnkMY1y2R/cHMCBsQ IbLgYgTIAJsIdxljBCmQ78Do4M8TFYSoQSo34gB2Q0pCB+ehFl7G Ml+NIdgRgSyP9BEVBywRAMXyMIUOPGCGe4aYHheYIfxHOY7MILzE EjVF6AYIzPMkzCjILSAAzMDAgCTxWTGtfUAK4Wh8A==<<<))
This results in an error:

Code: Select all

Cannot execute command.Error:(command):1:unexpected symbol near '>'
Ok, it looks like the syntax is incorrect, so I tried encapsulating the map string in quotes " ". That gives me a "nil" return.

Has anyone had any success with this command? I would be very grateful for mistakes to be pointed out.
Problems with the command: The map exchange string needs to be a string (the "" you mention). parse_map_exchange_string does not exist as a global function, it's game.parse_map_exchange_string. The result of game.parse_map_exchange_string is a table, it needs to be a string to be written to the file.

With all those things solved:

Code: Select all

/c game.write_file("my-map-settings.txt", serpent.block(game.parse_map_exchange_string(">>>eNpjYBBiYGYAgwZ7EOZgSc5PzIHxQJgrOb+gILVIN78oFVmYM 7moNCVVNz8TVXFqXmpupW5SYjGKYo7Movw8dBNYi0vy81BFSopSU 4uRRbhLixLzMktz0fUyMH6/sbyxoUWOAYT/1zMo/P8PwkDWA6BfQ JiBsQGiEigGA6zJOZlpaQwMCo5A7ASSZmRkrBZZ5/6waoo9I0SNn gOU8QEqciAJJuIJY/g54JRSgTFMkMwxBoPPSAyIpSVAK6CqOBwQD IhkC0iSkbH37dYF349dsGP8s/LjJd+kBHtGQ1eRdx+M1tkBJdlB/ mSCE7NmgsBOmFcYYGY+sIdK3bRnPHsGBN7YM7KCdIiACAcLIHHAm 5mBUYAPyFrQAyQUZBhgTrODGSPiwJgGBt9gPnkMY1y2R/cHMCBsQ IbLgYgTIAJsIdxljBCmQ78Do4M8TFYSoQSo34gB2Q0pCB+ehFl7G Ml+NIdgRgSyP9BEVBywRAMXyMIUOPGCGe4aYHheYIfxHOY7MILzE EjVF6AYIzPMkzCjILSAAzMDAgCTxWTGtfUAK4Wh8A==<<<")))
Output of write_file is found in Application directory/script-output.

Note: The format of the parsed map exchange string is different from the preset format. However they generally use the same terms, so you should be able to translate from one format to another.

Re: Help required - Usage of parse_map_exchange_string(map_exchange_string)

Posted: Wed Feb 05, 2020 3:20 pm
by Squelch
Wow!

I'm sure I had tried that too, but it must have been in combination with another nope.

Thank you @Bilka

[Edit]

As I thought. I was so close, but one typo in the long command line went unnoticed. I only found it once I had a working example to compare against my console history. I include my mistake here so others might benefit.
My incorrect attempt:

Code: Select all

/c game.write_file("my-map-settings.json",serpent.block(game.parse_map_exchange_string("">>>eNpjYBBiYGYAgwZ7EOZgSc5PzIHxQJgrOb+gILVIN78oFVmYM 7moNCVVNz8TVXFqXmpupW5SYjGKYo7Movw8dBNYi0vy81BFSopSU 4uRRbhLixLzMktz0fUyMH6/sbyxoUWOAYT/1zMo/P8PwkDWA6BfQ JiBsQGiEigGA6zJOZlpaQwMCo5A7ASSZmRkrBZZ5/6waoo9I0SNn gOU8QEqciAJJuIJY/g54JRSgTFMkMwxBoPPSAyIpSVAK6CqOBwQD IhkC0iSkbH37dYF349dsGP8s/LjJd+kBHtGQ1eRdx+M1tkBJdlB/ mSCE7NmgsBOmFcYYGY+sIdK3bRnPHsGBN7YM7KCdIiACAcLIHHAm 5mBUYAPyFrQAyQUZBhgTrODGSPiwJgGBt9gPnkMY1y2R/cHMCBsQ IbLgYgTIAJsIdxljBCmQ78Do4M8TFYSoQSo34gB2Q0pCB+ehFl7G Ml+NIdgRgSyP9BEVBywRAMXyMIUOPGCGe4aYHheYIfxHOY7MILzE EjVF6AYIzPMkzCjILSAAzMDAgCTxWTGtfUAK4Wh8A==<<<")))
@Bilka's correct example:

Code: Select all

/c game.write_file("my-map-settings.txt", serpent.block(game.parse_map_exchange_string(">>>eNpjYBBiYGYAgwZ7EOZgSc5PzIHxQJgrOb+gILVIN78oFVmYM 7moNCVVNz8TVXFqXmpupW5SYjGKYo7Movw8dBNYi0vy81BFSopSU 4uRRbhLixLzMktz0fUyMH6/sbyxoUWOAYT/1zMo/P8PwkDWA6BfQ JiBsQGiEigGA6zJOZlpaQwMCo5A7ASSZmRkrBZZ5/6waoo9I0SNn gOU8QEqciAJJuIJY/g54JRSgTFMkMwxBoPPSAyIpSVAK6CqOBwQD IhkC0iSkbH37dYF349dsGP8s/LjJd+kBHtGQ1eRdx+M1tkBJdlB/ mSCE7NmgsBOmFcYYGY+sIdK3bRnPHsGBN7YM7KCdIiACAcLIHHAm 5mBUYAPyFrQAyQUZBhgTrODGSPiwJgGBt9gPnkMY1y2R/cHMCBsQ IbLgYgTIAJsIdxljBCmQ78Do4M8TFYSoQSo34gB2Q0pCB+ehFl7G Ml+NIdgRgSyP9BEVBywRAMXyMIUOPGCGe4aYHheYIfxHOY7MILzE EjVF6AYIzPMkzCjILSAAzMDAgCTxWTGtfUAK4Wh8A==<<<")))
Where the extra double quote crept in, I'm not sure, but it's insidious nature was compounded by hiding in the lengthy console line, and reuse of it in the console history. Be warned.

[Note]
The mistake is so much more obvious when rendered on the forum. The console text against map tiles makes it much less apparent.