Page 1 of 1
How to read the file contents in the user data folder
Posted: Mon Aug 01, 2022 5:11 am
by sdgmlj
I saved one of my forms in the "script output" folder. The official wiki only said how to write it, but I didn't find out how to read it
local quickbar = {.........}
local text = game.table_to_json(quickbar)
game.write_file("save/quick-bar.json",text)
What command do I use to read the contents of this file? thank you
Re: How to read the file contents in the user data folder
Posted: Mon Aug 01, 2022 9:41 am
by sdgmlj
No one to help? I really need this answer
Re: How to read the file contents in the user data folder
Posted: Mon Aug 01, 2022 10:20 am
by boskid
There is no such thing as "read a file". When a script is running in a multiplayer game, every instance of the game would be trying to read the same file from different machine and if the content would be different a desync would happen. Primary way of mutable data storage is through a variable named "global" in Lua context, which is part of the save file.
Re: How to read the file contents in the user data folder
Posted: Mon Aug 01, 2022 10:40 am
by sdgmlj
boskid wrote: Mon Aug 01, 2022 10:20 am
There is no such thing as "read a file". When a script is running in a multiplayer game, every instance of the game would be trying to read the same file from different machine and if the content would be different a desync would happen. Primary way of mutable data storage is through a variable named "global" in Lua context, which is part of the save file.
Thank you for your reply. My idea is like this. I want to save the content of "quickbar" to a file so that it can be automatically read when I start a new game next time. So my idea can't be realized? Is that so?
Re: How to read the file contents in the user data folder
Posted: Mon Aug 01, 2022 12:50 pm
by Bilka
sdgmlj wrote: Mon Aug 01, 2022 10:40 am
Thank you for your reply. My idea is like this. I want to save the content of "quickbar" to a file so that it can be automatically read when I start a new game next time. So my idea can't be realized? Is that so?
Yes, you are correct that it cannot be realized in that form. There are alternative ways to transfer settings, for example by doing it like map exchange strings (player imports and exports). Here is a mod that does that with the quickbar:
https://mods.factorio.com/mod/quickbarimportexport
Re: How to read the file contents in the user data folder
Posted: Mon Aug 01, 2022 3:52 pm
by sdgmlj
Bilka wrote: Mon Aug 01, 2022 12:50 pm
sdgmlj wrote: Mon Aug 01, 2022 10:40 am
Thank you for your reply. My idea is like this. I want to save the content of "quickbar" to a file so that it can be automatically read when I start a new game next time. So my idea can't be realized? Is that so?
Yes, you are correct that it cannot be realized in that form. There are alternative ways to transfer settings, for example by doing it like map exchange strings (player imports and exports). Here is a mod that does that with the quickbar:
https://mods.factorio.com/mod/quickbarimportexport
thank you