convert map exchange string to map generator settings

Anything that prevents you from playing the game properly. Do you have issues playing for the game, downloading it or successfully running it on your computer? Let us know here.
Post Reply
User avatar
trad_emark
Inserter
Inserter
Posts: 27
Joined: Fri Sep 23, 2016 8:54 pm
Contact:

convert map exchange string to map generator settings

Post by trad_emark »

Is it possible to generate the map-settings.json and map-gen-settings.json from map exchange string or directly in the gui?

I know I can start a new game and upload the save to the server, but I would prefer to "acquire" the settings anyway, for multiple reasons.
- It would help me to better understand which value is which.
- It would allow me to generate save with some values outside ranges available in the gui (I especially like to set negative time or pollution factors for biters evolution :D ) and to set some of the other properties that aren't available in the gui at all.

Thanks for any hints :D

Casper042
Manual Inserter
Manual Inserter
Posts: 1
Joined: Thu Oct 03, 2019 12:36 am
Contact:

Re: convert map exchange string to map generator settings

Post by Casper042 »

Came to ask the same thing.

I would love to see either an in-game or a web based Exchange String to JSON converter.

For in-game, just have a JSON button on the normal Exchange String export screen perhaps.

billbo99
Fast Inserter
Fast Inserter
Posts: 131
Joined: Fri Nov 02, 2018 9:19 am
Contact:

Re: convert map exchange string to map generator settings

Post by billbo99 »

I am not near my home PC, but I believe these commands would generate the data

/c game.write_file("map-settings.json", serpent.block(game.map_settings))
/c game.write_file("map-gen-settings.json", serpent.block(player.surface.map_gen_settings))

This will output to the "script-output" folder.

IchibanDashi
Manual Inserter
Manual Inserter
Posts: 2
Joined: Sun Dec 22, 2019 1:21 am
Contact:

Re: convert map exchange string to map generator settings

Post by IchibanDashi »

I would also like to have this ability to output the map config files in JSON format from within Factorio. It would be helpful to be able to pass the config files to a server admin, instead of having to mess with save game files. Perhaps the server admin would like to tweak a few settings before spinning up the game?

I did try the commands that @billbo99 provided, but they didn't work. I'm not sure if it's because I'm running 0.18.6 or if it's something else.
This command doesn't give any errors:
/c game.write_file("map-settings.json", serpent.block(game.map_settings))
But, the contents of the file (and thus game.map_settings) are not what is expected:

Code: Select all

{
  __self = "userdata"
}
This command does give an error...
/c game.write_file("map-gen-settings.json", serpent.block(player.surface.map_gen_settings))
... as shown below:

Code: Select all

Cannot execute command. Error: (command):1:attempt to index global 'player' (a nil value)
I tried to do a little troubleshooting myself, but my knowledge of (Factorio's) Lua scripting is lacking.
For example: I can understand that the map settings would be in the game object, but why would the map generation settings be in player.surface?
Would it be foolish to presume that they might be stored in the same object?

Squelch
Filter Inserter
Filter Inserter
Posts: 346
Joined: Sat Apr 23, 2016 5:31 pm
Contact:

Re: convert map exchange string to map generator settings

Post by Squelch »

Try this:

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==<<<")))
from here

Note the output will need a bit of adjustment to be fully preset compatible.

IchibanDashi
Manual Inserter
Manual Inserter
Posts: 2
Joined: Sun Dec 22, 2019 1:21 am
Contact:

Re: convert map exchange string to map generator settings

Post by IchibanDashi »

I think I may have stumbled upon the answer:

Code: Select all

/c game.write_file("map-settings.json", serpent.block(game.parse_map_exchange_string(game.get_map_exchange_string())))
This basically gets the exchange string, runs it through the internal parser, runs it through the Serpent pretty printer, then outputs it all to the map-settings.json file in the script-output folder. (On Windows, this would be %APPDATA%\Factorio\script-output)
Both the map settings and the map gen settings get output to the same file (which might be fine, I think). [edit: I guess not]

Caveat: I haven't actually tested this on a headless server yet.
Also Caveat: This command will disable achievements. Save your game before you use this, if that's important to you.

EDIT: I should have refreshed the page before posting my answer. Thanks, Squelch, for that info. If I hadn't worked it out myself, I'm sure that would have pointed me in the right direction. Also good to know that the output isn't directly usable as the headless server config file. I'm sure a bit of comparison to the example config files will help clear that up!

Squelch
Filter Inserter
Filter Inserter
Posts: 346
Joined: Sat Apr 23, 2016 5:31 pm
Contact:

Re: convert map exchange string to map generator settings

Post by Squelch »

IchibanDashi wrote:
Tue Feb 18, 2020 3:22 am
I think I may have stumbled upon the answer:
..

EDIT: I should have refreshed the page before posting my answer. Thanks, Squelch, for that info. If I hadn't worked it out myself, I'm sure that would have pointed me in the right direction. Also good to know that the output isn't directly usable as the headless server config file. I'm sure a bit of comparison to the example config files will help clear that up!
No problem, and as you may have noticed, I too struggled in the same way. In fact it was deja vu there for a moment, and I had to check that I was not in my own topic :D

There is also
table_to_json(data) you might want to use too.
ie.

Code: Select all

/c game.write_file("my-map-settings.json", serpent.block(game.table_to_json(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==<<<"))))
Will output an unformatted .json that may help with the conversion.

larandar
Burner Inserter
Burner Inserter
Posts: 8
Joined: Sat Apr 13, 2019 3:51 pm
Contact:

Re: convert map exchange string to map generator settings

Post by larandar »

For the record, since this is the result in google when trying to export map-settings.json for a server, here is a combination of what work:

Code: Select all

 /c game.write_file("map-settings.json", game.table_to_json(game.parse_map_exchange_string(game.get_map_exchange_string())))
 /c game.write_file("map-gen-settings.json", game.table_to_json(game.player.surface.map_gen_settings))
Ready to be copy-pasted by anyone (and surely older-me ;) )

Post Reply

Return to “Technical Help”