Writing data to a file on a per-save basis

Place to get help with not working mods / modding interface.
Post Reply
swni
Long Handed Inserter
Long Handed Inserter
Posts: 91
Joined: Sat Mar 05, 2016 1:54 am
Contact:

Writing data to a file on a per-save basis

Post by swni »

I wrote a mod which writes information in a file as the game runs. I would like information from different saves to be separate from each other so the files don't clobber each other.

What I currently do is generate a random number from 0 to 2 ^ 30 in on_init, and use this to name a file in which the information is saved. It is very unlikely that two different saves will generate the same random number (unless you seed the map, I suppose...).

I am looking for a better approach for this problem. The random number method is not particularly elegant, and it is not user friendly to suggest to users to go find the most recently edited file whose name is a large number. Moreover, I ran into a minor issue with the invocation of math.random() altering the random numbers another mod got; it'd be nice to avoid randomness so these sorts of issues don't show up in the future.

Any suggestions?

Bilka
Factorio Staff
Factorio Staff
Posts: 3169
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Writing data to a file on a per-save basis

Post by Bilka »

You could make users choose a name on init.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

swni
Long Handed Inserter
Long Handed Inserter
Posts: 91
Joined: Sat Mar 05, 2016 1:54 am
Contact:

Re: Writing data to a file on a per-save basis

Post by swni »

That sounds good, I had no idea that was possible. Is this using LuaGui in some way? I went looking around but the only thing relevant I could find was game.show_message_dialog().

I guess I could implement a command which is typed at the console for selecting a name. (But I think that would disable achievements then?)

Post Reply

Return to “Modding help”