Is it possible to export and import information in the same format as the plans?
Is it possible to export and import information in the same format as the plans?
I just want to know if there is a way to access the functions that are used to import and export the information, such as the plans or the map.
I want to use those functions to get information from my mod.
If not possible, no problem, I'll build my own function, but I hope they can be used.
I want to use those functions to get information from my mod.
If not possible, no problem, I'll build my own function, but I hope they can be used.
Solo entiendo español, pero si tu también lo entiendes, escríbeme


Everything i write in English is translated by Deepl.

Re: Is it possible to export and import information in the same format as the plans?
I suppose not
Solo entiendo español, pero si tu también lo entiendes, escríbeme


Everything i write in English is translated by Deepl.

Re: Is it possible to export and import information in the same format as the plans?
Generic JSON import/export are available: https://lua-api.factorio.com/latest/Lua ... n_to_table
And mods can import/export blueprints into items (not the Library): https://lua-api.factorio.com/latest/Lua ... port_stack
And mods can import/export blueprints into items (not the Library): https://lua-api.factorio.com/latest/Lua ... port_stack
My mods: Multiple Unit Train Control, RGB Pipes, Shipping Containers, Rocket Log, Smart Artillery Wagons.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
Re: Is it possible to export and import information in the same format as the plans?
I appreciate the help, but I don't understand how to use these functionsrobot256 wrote: Fri Mar 04, 2022 9:22 pm And mods can import/export blueprints into items (not the Library): https://lua-api.factorio.com/latest/Lua ... port_stack
export_stack( ) and import_stack( data ); and if I can use it for this data:
Code: Select all
[ "JSON " ] = '{"zzYAIM":{"maximum-stack-size":{"Players":{"yaim904":{}}}}}'
[ "LUA" ] = {
[ 'zzYAIM' ] = {
[ 'maximum-stack-size' ] = {
[ 'Players' ] = {
[ 'yaim904' ] = { },
},
},
},
}
I just want to use the encryption they use.
Solo entiendo español, pero si tu también lo entiendes, escríbeme


Everything i write in English is translated by Deepl.

Re: Is it possible to export and import information in the same format as the plans?
Export_stack function gives an encoded JSON string. Json_to_table turns that JSON strings into a lua table you can print (with serpent.block formatting) and edit. Then re-encode the new table with table_to_json and put it back into an item with import_stack. The table/string data includes whether it is a blueprint, upgrade or deconatruction planner. At least I think this is how it works.
My mods: Multiple Unit Train Control, RGB Pipes, Shipping Containers, Rocket Log, Smart Artillery Wagons.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
Re: Is it possible to export and import information in the same format as the plans?
I still don't understand, but thank you for responding.
Solo entiendo español, pero si tu también lo entiendes, escríbeme


Everything i write in English is translated by Deepl.

Re: Is it possible to export and import information in the same format as the plans?
Maybe you could explain in more detail what you want to accomplish? I just saw the word "map" and that is unrelated to the blueprint API, so I'm not sure what you want after all.
My mods: Multiple Unit Train Control, RGB Pipes, Shipping Containers, Rocket Log, Smart Artillery Wagons.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
Re: Is it possible to export and import information in the same format as the plans?
I have this data, I want to use the export function that Factorio has.
An example of the function is: How to export the blueprints or the map configuration.
Code: Select all
[ "JSON " ] = '{"zzYAIM":{"maximum-stack-size":{"Players":{"yaim904":{}}}}}'
[ "LUA" ] = {
[ 'zzYAIM' ] = {
[ 'maximum-stack-size' ] = {
[ 'Players' ] = {
[ 'yaim904' ] = { },
},
},
},
}
Code: Select all
0eNrcvWtyW0mSrTsX/mxL1N3xjii7tyfSViaDKEiCFR8ykso+aW05gDOQM7EzkgtQKWCL2L5jfYF6WOpPVydFrojt4e7xWrH8f27e333dfXnaP7zc/PV/bva3jw/PN3/9r/+5ed5/etjeHX/28tuX3c1fb/Yvu/ubX24etvfH/3p+eXzYbT5+fXrY3u5ufv/lZv/wYfe/bv7qfv+l+7fb5+fd/fu7/cOnzf329vP+AORnEF6AuNu+n/
Solo entiendo español, pero si tu también lo entiendes, escríbeme


Everything i write in English is translated by Deepl.

Re: Is it possible to export and import information in the same format as the plans?
Do you mean that you want to export your custom data table *as though it were a blueprint*? Not to export an actual blueprint? Or do you want to do something with blueprints that you cannot already with the import/export shortcut buttons?
To export the custom data table, you would use https://lua-api.factorio.com/latest/Lua ... le_to_json
To export:
Map exchange string can be exported from a game: https://lua-api.factorio.com/latest/Lua ... nge_string
To export:
or
Map exchange string can be parsed by mod code to show its meaning: https://lua-api.factorio.com/latest/Lua ... nge_string
To parse:
or
Blueprint data can be accessed if you have a LuaItemStack object handle. For example, hold it in your cursor and run
To export the custom data table, you would use https://lua-api.factorio.com/latest/Lua ... le_to_json
To export:
Code: Select all
/c game.write_file( "export_string.txt", game.table_to_json( my_table_variable ) )
Map exchange string can be exported from a game: https://lua-api.factorio.com/latest/Lua ... nge_string
To export:
Code: Select all
/c game.print( game.get_map_exchange_string() )
Code: Select all
/c game.write_file( "map_string.txt", game.get_map_exchange_string() )
To parse:
Code: Select all
/c game.print( serpent.block( game.parse_map_exchange_string( game.get_map_exchange_string() ) ) )
Code: Select all
/c game.write_file( "map_data.txt", serpent.block( game.parse_map_exchange_string( game.get_map_exchange_string() ) ) )
Blueprint data can be accessed if you have a LuaItemStack object handle. For example, hold it in your cursor and run
Code: Select all
/c game.print( game.player.cursor_stack.export_stack() )
My mods: Multiple Unit Train Control, RGB Pipes, Shipping Containers, Rocket Log, Smart Artillery Wagons.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
Re: Is it possible to export and import information in the same format as the plans?
robot256 wrote: Fri Mar 11, 2022 2:17 pm Do you mean that you want to export your custom data table *as though it were a blueprint*?
Yes!!
But from what I understand, it only works for some parts and structures of the game, am I correct?Solo entiendo español, pero si tu también lo entiendes, escríbeme


Everything i write in English is translated by Deepl.

Re: Is it possible to export and import information in the same format as the plans?
My first example is what you need. The rest of my examples use the built in functions to export map share strings and blueprint/planner strings. For data that is not a map config or blueprint, you can make your own Lua table in your mod's code, copying in the parameters you want out of the LuaObjects, and export the table with game.table_to_json(). Doing this, you can export any information available through the mod API. You cannot pass a LuaObject (like a LuaPlayer or LuaEntity) directly to game.table_to_json().
My mods: Multiple Unit Train Control, RGB Pipes, Shipping Containers, Rocket Log, Smart Artillery Wagons.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
Re: Is it possible to export and import information in the same format as the plans?
Yes, you're right, that function would convert any table from Lua to JSon; but, the result would be in JSon, not in the peculiar format of get_map_exchange_string( ).
I think I'll have to create my encryptor.
Solo entiendo español, pero si tu también lo entiendes, escríbeme


Everything i write in English is translated by Deepl.

Re: Is it possible to export and import information in the same format as the plans?
Oh, sorry, I should have tested the function myself. Yes, the blueprints uses a binary-to-base-64 translator. Which is also in the API! Try
Code: Select all
game.encode_string(game.table_to_json(my_table))
My mods: Multiple Unit Train Control, RGB Pipes, Shipping Containers, Rocket Log, Smart Artillery Wagons.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
Re: Is it possible to export and import information in the same format as the plans?
I tried it, it's what I'm looking for, thank you very much.robot256 wrote: Fri Mar 11, 2022 11:01 pm Oh, sorry, I should have tested the function myself. Yes, the blueprints uses a binary-to-base-64 translator. Which is also in the API! TryCode: Select all
game.encode_string(game.table_to_json(my_table))
To learn what I did wrong, why did you take so long to understand what I was asking?
Solo entiendo español, pero si tu también lo entiendes, escríbeme


Everything i write in English is translated by Deepl.

Re: Is it possible to export and import information in the same format as the plans?
Well, half the trouble was that I forgot the encode_string() function existed until today! And also that I forgot JSON is plaintext and not encoded data.
Your wording of "access the functions that..." confused me, because there are purpose-made API functions for plans and maps which are unrelated to the ones for generic data. I might have understood better if you had started by describing the result you wanted rather than a method of getting it.
For example, "I know the game can put blueprints and map data into a compressed string of characters for easy copy and paste. How can I put my own arbitrary data into a similar string of characters?"
Your wording of "access the functions that..." confused me, because there are purpose-made API functions for plans and maps which are unrelated to the ones for generic data. I might have understood better if you had started by describing the result you wanted rather than a method of getting it.
For example, "I know the game can put blueprints and map data into a compressed string of characters for easy copy and paste. How can I put my own arbitrary data into a similar string of characters?"
My mods: Multiple Unit Train Control, RGB Pipes, Shipping Containers, Rocket Log, Smart Artillery Wagons.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.