Require all files in a scenario directory.

Place to get help with not working mods / modding interface.
Post Reply
User avatar
MewMew
Inserter
Inserter
Posts: 28
Joined: Thu May 19, 2016 11:02 am
Contact:

Require all files in a scenario directory.

Post by MewMew » Mon Sep 17, 2018 1:18 am

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!

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 2604
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Require all files in a scenario directory.

Post by eradicator » Mon Sep 17, 2018 7:33 am

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.
Author of: Hand Crank Generator, Screenshot Hotkey 2.0
Mod support languages: 日本語, Deutsch, English

User avatar
MewMew
Inserter
Inserter
Posts: 28
Joined: Thu May 19, 2016 11:02 am
Contact:

Re: Require all files in a scenario directory.

Post by MewMew » Mon Sep 17, 2018 11:07 am

Sad, it would be so useful if this was doable somehow within the game.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 2604
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Require all files in a scenario directory.

Post by eradicator » Mon Sep 17, 2018 1:58 pm

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 :).
Author of: Hand Crank Generator, Screenshot Hotkey 2.0
Mod support languages: 日本語, Deutsch, English

User avatar
MewMew
Inserter
Inserter
Posts: 28
Joined: Thu May 19, 2016 11:02 am
Contact:

Re: Require all files in a scenario directory.

Post by MewMew » Mon Sep 17, 2018 2:04 pm

Gathering data across play sessions in a comfortable nice way. Most useful for multiplayer values.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 2604
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Require all files in a scenario directory.

Post by eradicator » Mon Sep 17, 2018 7:06 pm

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).
Author of: Hand Crank Generator, Screenshot Hotkey 2.0
Mod support languages: 日本語, Deutsch, English

User avatar
MewMew
Inserter
Inserter
Posts: 28
Joined: Thu May 19, 2016 11:02 am
Contact:

Re: Require all files in a scenario directory.

Post by MewMew » 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.

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 2688
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Require all files in a scenario directory.

Post by DaveMcW » Tue Sep 18, 2018 12:27 am

Set the third parameter of game.write_file() to true, it appends everything to a single file.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 2604
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Require all files in a scenario directory.

Post by eradicator » Tue Sep 18, 2018 8:14 am

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.
Author of: Hand Crank Generator, Screenshot Hotkey 2.0
Mod support languages: 日本語, Deutsch, English

User avatar
MewMew
Inserter
Inserter
Posts: 28
Joined: Thu May 19, 2016 11:02 am
Contact:

Re: Require all files in a scenario directory.

Post by MewMew » Tue Sep 18, 2018 9:38 am

Yes and to load them back in, it would be helpful to just be able load all files in a directory.

Post Reply

Return to “Modding help”

Who is online

Users browsing this forum: No registered users and 2 guests