Hi
I'm looking at the list of methods available through the API.
I read on the wiki that there is a read_file method.
https://wiki.factorio.com/index.php?tit ... write_file
I wonder what it's used for, since I see no read_file() method :p
Is it an error on the wiki ?
Thanks !
game.write_file() : why no read_file ?
-
- Inserter
- Posts: 46
- Joined: Tue Mar 29, 2016 10:31 am
- Contact:
Re: game.write_file() : why no read_file ?
Writing files can easily be done in a deterministic way - the contents written out won't change the game state at all.
Reading files would be completely non-deterministic - the contents of the file could (and would most likely) change between every save load and be different on each peer in a multiplayer environment.
Essentially, it doesn't work if you want to support replays and it doesn't work if you want to support multiplayer. There's also the entire security issue that would need to be addressed (what can a mod read, how much at a time, and so on) that makes it just not worth the time to look into.
Reading files would be completely non-deterministic - the contents of the file could (and would most likely) change between every save load and be different on each peer in a multiplayer environment.
Essentially, it doesn't work if you want to support replays and it doesn't work if you want to support multiplayer. There's also the entire security issue that would need to be addressed (what can a mod read, how much at a time, and so on) that makes it just not worth the time to look into.
If you want to get ahold of me I'm almost always on Discord.
Re: game.write_file() : why no read_file ?
One way to make it deterministic would be something like this:
create a function read_file(name) in the LuaPlayer class/interface. The behavior is as follows:
create a function read_file(name) in the LuaPlayer class/interface. The behavior is as follows:
Code: Select all
function read_file(player, name)
local str
if game.is_live then
if player == local_player then
str = read_from_os(name)
send_to_peers(player, name, str)
else
str = read_received(player, name)
end
record_in_replay(player, name, str)
else
-- in replay
str = load_from_repaly(player, name)
end
return str
end