game.read_file ?

Place to get help with not working mods / modding interface.
mophydeen
Filter Inserter
Filter Inserter
Posts: 529
Joined: Sun Nov 22, 2015 5:02 pm
Contact:

game.read_file ?

Post by mophydeen »

there is a game.write_file(filename, data, append, for_player) method.

Is there a way to read it back in ?

daniel34
Global Moderator
Global Moderator
Posts: 2761
Joined: Thu Dec 25, 2014 7:30 am
Contact:

Re: game.read_file ?

Post by daniel34 »

No. The Factorio API doesn't have a method to read files because this would break determinism. In multiplayer all clients and the server would need to have the same exact files (similar to how mods have to be the same), if just one file was slightly different or missing this would lead to a desync. In singleplayer if you wanted to replay a savegame you would need to read the exact same files as when the savegame was originally played.

See also:
quick links: log file | graphical issues | wiki

mophydeen
Filter Inserter
Filter Inserter
Posts: 529
Joined: Sun Nov 22, 2015 5:02 pm
Contact:

Re: game.read_file ?

Post by mophydeen »

Ty.

I would not use it for all players just for local stuff.

Eg. Loading a saved blueprint string from file.
It's saved in a file which is a great. Only reloading it back in the game is a long process of opening the file, copy, back to game, paste ..

daniel34
Global Moderator
Global Moderator
Posts: 2761
Joined: Thu Dec 25, 2014 7:30 am
Contact:

Re: game.read_file ?

Post by daniel34 »

If you are very experienced it is possible to patch factorio.exe, this unlocks the io lua library which you then can use in your mod to read from or write to any file: viewtopic.php?f=120&t=23655

Related: viewtopic.php?f=28&t=23519#p152528
Rseding91 wrote:The standard game is not getting un-sandboxed.

I was thinking about it and had the idea that we might provide a flag that mods could use or perhaps a startup flag that would be required that enabled all of the unsafe and non-deterministic methods that aren't normally available. It would at the same time disable multiplayer and replays but this is all just ideas - I'm not sure if it would be worth the time at this point.
quick links: log file | graphical issues | wiki

mophydeen
Filter Inserter
Filter Inserter
Posts: 529
Joined: Sun Nov 22, 2015 5:02 pm
Contact:

Re: game.read_file ?

Post by mophydeen »

daniel34 wrote:If you are very experienced it is possible to patch factorio.exe, this unlocks the io lua library which you then can use in your mod to read from or write to any file: viewtopic.php?f=120&t=23655

Related: viewtopic.php?f=28&t=23519#p152528
Rseding91 wrote:The standard game is not getting un-sandboxed.

I was thinking about it and had the idea that we might provide a flag that mods could use or perhaps a startup flag that would be required that enabled all of the unsafe and non-deterministic methods that aren't normally available. It would at the same time disable multiplayer and replays but this is all just ideas - I'm not sure if it would be worth the time at this point.

Ty for you responses.

locally patching it's my goal.
You references show the devs aren't interested in giving access to it. Not even a local folder inside the factorio path. I understand the security risks involved.

note: I'm not looking for a normal mod way but a save-file way :)

Plorntus
Burner Inserter
Burner Inserter
Posts: 14
Joined: Mon Nov 24, 2014 10:43 am
Contact:

Re: game.read_file ?

Post by Plorntus »

I think the whole determinism argument is a bit of a crappy reason in my opinion. Just simply telling the user not to use it to make something happen in the game (other than loading blueprints or whatever) is enough.

Its like saying disallow mods because a user can accidentally write incorrect code (ie not using the right syntax), of course they can but as long as they know not to then it shouldnt be an issue.

Things like two way sockets or reading a file can enable some very cool things such as live online maps or telementary for the game (eg Kerbal Space Programs telamechus mod).

User avatar
HanziQ
Former Staff
Former Staff
Posts: 630
Joined: Fri Mar 27, 2015 7:07 am
Contact:

Re: game.read_file ?

Post by HanziQ »

Plorntus wrote:I think the whole determinism argument is a bit of a crappy reason in my opinion. Just simply telling the user not to use it to make something happen in the game (other than loading blueprints or whatever) is enough.

Its like saying disallow mods because a user can accidentally write incorrect code (ie not using the right syntax), of course they can but as long as they know not to then it shouldnt be an issue.

Things like two way sockets or reading a file can enable some very cool things such as live online maps or telementary for the game (eg Kerbal Space Programs telamechus mod).
1) People don't know how to write incorrect code. People don't follow instructions like "Don't use this method, it will break determinism and it will desync". This has been proven time and time again.
2) When something like this happens, and someone downloads such broken mod and it breaks the game, where do they report it? To the mod author? No. To us, we have to go in, figure out whether the problem lies with our code or someone elses and send them their way. That takes a lot of our time and it's just wasteful. But it does have a simple solution - not including things like game.read_file.

Plorntus
Burner Inserter
Burner Inserter
Posts: 14
Joined: Mon Nov 24, 2014 10:43 am
Contact:

Re: game.read_file ?

Post by Plorntus »

HanziQ wrote:
Plorntus wrote:I think the whole determinism argument is a bit of a crappy reason in my opinion. Just simply telling the user not to use it to make something happen in the game (other than loading blueprints or whatever) is enough.

Its like saying disallow mods because a user can accidentally write incorrect code (ie not using the right syntax), of course they can but as long as they know not to then it shouldnt be an issue.

Things like two way sockets or reading a file can enable some very cool things such as live online maps or telementary for the game (eg Kerbal Space Programs telamechus mod).
1) People don't know how to write incorrect code. People don't follow instructions like "Don't use this method, it will break determinism and it will desync". This has been proven time and time again.
2) When something like this happens, and someone downloads such broken mod and it breaks the game, where do they report it? To the mod author? No. To us, we have to go in, figure out whether the problem lies with our code or someone elses and send them their way. That takes a lot of our time and it's just wasteful. But it does have a simple solution - not including things like game.read_file.
I guess, I dunno I just would have thought more people (especially those creating the mods) would follow what the documentation or information regarding what a method says, perhaps hiding the method behind some massive warning banner would work in the documentation, I know its a little more work for you guys but that'd seem like a nice compromise especially since there are a lot of questions asking for this. I dont see how the reporting the issue to you rather than the mod creators would be different when an unexpected issue occurs in the game because of a mod normally but I'll trust what you say is right in any case (as you'd of course know from experience).

You'd also hope that someone would be using the mod and realise its an issue with the mod rather than the base game providing the game worked before enabling it.

I just hope at some point perhaps later on you'd reconsider as it really would enable some cool additions to the game that you perhaps do not want to implement yourselves.

orzelek
Smart Inserter
Smart Inserter
Posts: 3921
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: game.read_file ?

Post by orzelek »

HanziQ wrote:
Plorntus wrote:I think the whole determinism argument is a bit of a crappy reason in my opinion. Just simply telling the user not to use it to make something happen in the game (other than loading blueprints or whatever) is enough.

Its like saying disallow mods because a user can accidentally write incorrect code (ie not using the right syntax), of course they can but as long as they know not to then it shouldnt be an issue.

Things like two way sockets or reading a file can enable some very cool things such as live online maps or telementary for the game (eg Kerbal Space Programs telamechus mod).
1) People don't know how to write correct code. People don't follow instructions like "Don't use this method, it will break determinism and it will desync". This has been proven time and time again.
2) When something like this happens, and someone downloads such broken mod and it breaks the game, where do they report it? To the mod author? No. To us, we have to go in, figure out whether the problem lies with our code or someone elses and send them their way. That takes a lot of our time and it's just wasteful. But it does have a simple solution - not including things like game.read_file.
Fixed that one for you :D

User avatar
HanziQ
Former Staff
Former Staff
Posts: 630
Joined: Fri Mar 27, 2015 7:07 am
Contact:

Re: game.read_file ?

Post by HanziQ »

orzelek wrote:
HanziQ wrote:
Plorntus wrote:I think the whole determinism argument is a bit of a crappy reason in my opinion. Just simply telling the user not to use it to make something happen in the game (other than loading blueprints or whatever) is enough.

Its like saying disallow mods because a user can accidentally write incorrect code (ie not using the right syntax), of course they can but as long as they know not to then it shouldnt be an issue.

Things like two way sockets or reading a file can enable some very cool things such as live online maps or telementary for the game (eg Kerbal Space Programs telamechus mod).
1) People don't know how to write correct code. People don't follow instructions like "Don't use this method, it will break determinism and it will desync". This has been proven time and time again.
2) When something like this happens, and someone downloads such broken mod and it breaks the game, where do they report it? To the mod author? No. To us, we have to go in, figure out whether the problem lies with our code or someone elses and send them their way. That takes a lot of our time and it's just wasteful. But it does have a simple solution - not including things like game.read_file.
Fixed that one for you :D
Yeah, my bad :D but it did get my point across.

User avatar
cpeosphoros
Inserter
Inserter
Posts: 40
Joined: Fri Dec 23, 2016 10:57 pm
Contact:

Re: game.read_file ?

Post by cpeosphoros »

Plorntus wrote:I guess, I dunno I just would have thought more people (especially those creating the mods) would follow what the documentation or information regarding what a method says, perhaps hiding the method behind some massive warning banner would work in the documentation, I know its a little more work for you guys but that'd seem like a nice compromise especially since there are a lot of questions asking for this. I dont see how the reporting the issue to you rather than the mod creators would be different when an unexpected issue occurs in the game because of a mod normally but I'll trust what you say is right in any case (as you'd of course know from experience).

You'd also hope that someone would be using the mod and realise its an issue with the mod rather than the base game providing the game worked before enabling it.

I just hope at some point perhaps later on you'd reconsider as it really would enable some cool additions to the game that you perhaps do not want to implement yourselves.
For one, the documentation is just getting up to a point where it's detailed to a point where it's useful. Just have a look at some mod-related stuff (mostly the guides) here in the forums from six months ago.

And the state the docs are now should earn really large kudos to the dev team. Being a programmer myself, I know it's a really huge pita to keep detailed API documentation up to date (and keeping compatibility, etc).

For two, you are helplessly hopeful for users' ability to not working havoc on a system ;) . Add a feature to a software which the users should not activate unless in certain very specific conditions, on pain of crashing the whole system, and the users will certainly activate it in all but those conditions.

Post Reply

Return to “Modding help”