Page 1 of 1

Require all files in a scenario directory.

Posted: Mon Sep 17, 2018 1:18 am
by MewMew
There is a directory with a ton of files in a scenario folder.

You don´t know the names of the files.

Is it possible to find all the files in that folder and require / load them all from within a scenario script?

Would love if this was doable somehow!

Re: Require all files in a scenario directory.

Posted: Mon Sep 17, 2018 7:33 am
by eradicator
MewMew wrote:
Mon Sep 17, 2018 1:18 am
Would love if this was doable somehow!
No love for you today. This is not supported in factorio. You have to explicitly require every file you need.
If you don't care for the loading order of all the files you can probably make a quick script with dir/ls that automatically creates the requirements for you.

Re: Require all files in a scenario directory.

Posted: Mon Sep 17, 2018 11:07 am
by MewMew
Sad, it would be so useful if this was doable somehow within the game.

Re: Require all files in a scenario directory.

Posted: Mon Sep 17, 2018 1:58 pm
by eradicator
What is your usecase for loading arbitrary files? If it's just "it's annoying to write all the requires" that's just not a very good usecase :).

Re: Require all files in a scenario directory.

Posted: Mon Sep 17, 2018 2:04 pm
by MewMew
Gathering data across play sessions in a comfortable nice way. Most useful for multiplayer values.

Re: Require all files in a scenario directory.

Posted: Mon Sep 17, 2018 7:06 pm
by eradicator
MewMew wrote:
Mon Sep 17, 2018 2:04 pm
Gathering data across play sessions in a comfortable nice way. Most useful for multiplayer values.
I have no clue what you're trying to do there. If you need help you'll have to give more details (if not, then not :p).

Re: Require all files in a scenario directory.

Posted: Mon Sep 17, 2018 10:08 pm
by MewMew
Something, like, writing the playtimes of players every session to files so you can gather a total playtime amount. Things like that.

Re: Require all files in a scenario directory.

Posted: Tue Sep 18, 2018 12:27 am
by DaveMcW
Set the third parameter of game.write_file() to true, it appends everything to a single file.

Re: Require all files in a scenario directory.

Posted: Tue Sep 18, 2018 8:14 am
by eradicator
MewMew wrote:
Mon Sep 17, 2018 10:08 pm
Something, like, writing the playtimes of players every session to files so you can gather a total playtime amount. Things like that.
That data is already available via the API:
LuaPlayer wrote: afk_time :: uint [R] How many ticks since the last action of this player
online_time :: uint [R] How many ticks did this player spend playing this save (all sessions combined)
And even if it wasn't i see no need to store it into files instead of into the saves global data. So i'm still uncertain what your actual usecase might be @ "Things like that".

Files written via game.write_file() can't be read back into a running game even if you did know the file names, becaues they're not in a directory accessible to the lua state. You'd have to manually move them into the mod/scenario after writing them.

Re: Require all files in a scenario directory.

Posted: Tue Sep 18, 2018 9:38 am
by MewMew
Yes and to load them back in, it would be helpful to just be able load all files in a directory.