How to read the file contents in the user data folder

Place to get help with not working mods / modding interface.
Post Reply
sdgmlj
Fast Inserter
Fast Inserter
Posts: 127
Joined: Sun Jul 04, 2021 11:12 pm
Contact:

How to read the file contents in the user data folder

Post 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

sdgmlj
Fast Inserter
Fast Inserter
Posts: 127
Joined: Sun Jul 04, 2021 11:12 pm
Contact:

Re: How to read the file contents in the user data folder

Post by sdgmlj »

No one to help? I really need this answer

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2241
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: How to read the file contents in the user data folder

Post 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.

sdgmlj
Fast Inserter
Fast Inserter
Posts: 127
Joined: Sun Jul 04, 2021 11:12 pm
Contact:

Re: How to read the file contents in the user data folder

Post 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?

Bilka
Factorio Staff
Factorio Staff
Posts: 3128
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: How to read the file contents in the user data folder

Post 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
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

sdgmlj
Fast Inserter
Fast Inserter
Posts: 127
Joined: Sun Jul 04, 2021 11:12 pm
Contact:

Re: How to read the file contents in the user data folder

Post 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

Post Reply

Return to “Modding help”