Writing data to a file on a per-save basis
Posted: Thu Dec 20, 2018 1:57 pm
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?
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?