Require all files in a scenario directory.

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

Require all files in a scenario directory.

Post 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!

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

Re: Require all files in a scenario directory.

Post 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.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

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

Re: Require all files in a scenario directory.

Post by MewMew »

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

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

Re: Require all files in a scenario directory.

Post 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 :).
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

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

Re: Require all files in a scenario directory.

Post by MewMew »

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

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

Re: Require all files in a scenario directory.

Post 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).
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

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

Re: Require all files in a scenario directory.

Post by MewMew »

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: 3699
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Require all files in a scenario directory.

Post by DaveMcW »

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: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Require all files in a scenario directory.

Post 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.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

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

Re: Require all files in a scenario directory.

Post by MewMew »

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”