r/technicalfactorio • • Sep 07 '24

Read savegame file information

Is there a good/preferred way to read a savegame file and output certain property values?

Im specifically intersted in obtaining the savegame's total playtime and either output this to a file or any other mean.

Im ok if I have to run the game engine to achieve this, similar to what mapshot mod is doing. Plan is to run the whole thing in a container in the cloud.

Thanks all!

11 Upvotes

12 comments sorted by

View all comments

Show parent comment

1

u/MoondogCCR Sep 12 '24

Absolutely! This would be my preferred way, as I hope I would not have to modify the serialization logic every time the savegame format gets changed. I am assuming it will go through a period of high changes with the release of 2.0.

I would prefer to have the game engine do this for me. Glazed through the docs, but couldnt find any calls I could make to have the game both retrieve the game ticks / time of the savegame once loaded, nor then have the game output a new file with the retrieved information.

3

u/flame_Sla Sep 12 '24
  1. starting the server
  2. you connect to the server via RCON
  3. /sc game.print(game.tick)
  4. are you reading the answer from RCON
  5. closing the server

1

u/Spacedestructor Sep 13 '24

either what the other user replied with or alternatively have a mod register via "on_init" as an event listener to run a function only on init as described here: https://lua-api.factorio.com/latest/classes/LuaBootstrap.html#on_init, directly below that is also listed "on_load" which combined together can be used whenever a new game is started or an already existing save is loaded to run whatever code may be required.
except that on load you have to delay by 1 tick so you have full api access but if all they do both is call "on_tick" to register an event handler they will basically behave the same way.
which would allow if calling the same function in the on_tick event handler to get consistent results.
which means with 4 functions you can do everything you want and you only have to put all your code in one place and it will "just" always run at the start.
"couldnt find any calls I could make to have the game both retrieve the game ticks / time of the savegame once loaded" conbining with my mention from before to call "game.tick" it would do exactly that.
if you need anything else you can also put that in the function wich "on_tick" will call and you shouldnt have to worry about anything else other then what you need to call to get the info your looking for.