Another request for something like game.read_file()

Things that we aren't going to implement
Post Reply
User avatar
Versepelles
Long Handed Inserter
Long Handed Inserter
Posts: 70
Joined: Sat May 28, 2016 1:42 pm
Contact:

Another request for something like game.read_file()

Post by Versepelles »

There has been previous discussion on the topic (viewtopic.php?f=28&t=16824&hilit=read_file), but I would like to show more interest in simple file i/o.

The motivation behind this is to have mod history persistent beyond a single game, like this thread requests, where a player wants a chest that could save its contents between saves. This requires output, which is currently available in the form of game.write_file(...), and input, which is currently unavailable.

User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Another request for something like game.read_file()

Post by aubergine18 »

What if there was a persistent settings folder (separate to script output directory), where each mod can read/write a JSON file through a very strict API? The file name would be based on mod name with extension '.json'.

API could be something like:

Code: Select all

Script.set(key[,value]) -- nil value deletes key

local val = Script.get(key[,default]) -- optional default if key not found

Script.reset() -- reset (delete?) settings file
File creation, etc., is automated within the API.

Note: This wouldn't replace any of the existing file I/O stuff in the script output directory.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Another request for something like game.read_file()

Post by prg »

Now what if different people in a multiplayer game have different settings?
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Another request for something like game.read_file()

Post by aubergine18 »

Once an MP game starts, the API methods (.get(), .set(), .reset()) could be disabled.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.

User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1190
Joined: Wed May 18, 2016 4:55 pm
Contact:

Re: Another request for something like game.read_file()

Post by Mooncat »

Seems there is still no read_file in 0.15, I want to have a small bump for this request.

Sorry if this has been discussed, but what if read_file only reads the file on server if it is run in MP?
The current write_file allows writing file only on server, so I think it is already possible to make file IO only occurs on server?

Rseding91
Factorio Staff
Factorio Staff
Posts: 13210
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Another request for something like game.read_file()

Post by Rseding91 »

Currently it's not possible because it would break determinism (replays and MP).
If you want to get ahold of me I'm almost always on Discord.

User avatar
steinio
Smart Inserter
Smart Inserter
Posts: 2633
Joined: Sat Mar 12, 2016 4:19 pm
Contact:

Re: Another request for something like game.read_file()

Post by steinio »

Rseding91 wrote:Currently it's not possible because it would break determinism (replays and MP).
I wonder who really uses replays. Nice but abandoned feature.

Greetings steinio
Image

Transport Belt Repair Man

View unread Posts

BenSeidel
Filter Inserter
Filter Inserter
Posts: 584
Joined: Tue Jun 28, 2016 1:44 am
Contact:

Re: Another request for something like game.read_file()

Post by BenSeidel »

Why does noone just suggest that the file reading, date/time reading etc be placed on the player script object? Then when you read a file you have already specified who you are reading it from. I don't see any difference between reading a file and reading the console input. Both are non-deterministic and are associated with a player. As for the replay, just save the file contents? Just as if a mod saves too much data to a table and the file gets too big, if you read a file that is big you will get a save that is big.

User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1190
Joined: Wed May 18, 2016 4:55 pm
Contact:

Re: Another request for something like game.read_file()

Post by Mooncat »

Rseding91 wrote:Currently it's not possible because it would break determinism (replays and MP).
Thanks for re-reviewing this request!

About MP, as I said, just read the file on server so everyone has the same file to read?

About replay...
steinio wrote:I wonder who really uses replays. Nice but abandoned feature.
I think someone will find it useful, since there is a replay mod in Minecraft. :P
And I have just tried it the first time, I think it is quite good. Though it shouldn't quit immediately when the replay ends.

Anyway, about read_file in replay...
Normally, after reading a file, we use the data to do actions, like creating a GUI, placing some entities on the map.
How about just record those actions? That way you don't even need to record the whole file in replay. :)
i.e. only record the visible actions. "Reading a file" is hidden, so there is no need to record it. The only things that need to be recorded is the visible actions after reading a file. And that should have already been done in the current APIs? ;)

quyxkh
Smart Inserter
Smart Inserter
Posts: 1028
Joined: Sun May 08, 2016 9:01 am
Contact:

Re: Another request for something like game.read_file()

Post by quyxkh »

I think replays would get used more if there was an option to decouple/recouple the replay and recorded view -- so you could e.g. load a replay, set the speed to x64, bring up the map, and watch. Having replay save checkpoints so you could skip back would awesome.

rater193
Burner Inserter
Burner Inserter
Posts: 10
Joined: Wed Apr 19, 2017 10:37 pm
Contact:

Re: Another request for something like game.read_file()

Post by rater193 »

ugh, i really wish there was a way to read files :(

Post Reply

Return to “Won't implement”