Enabling scripted saves in replay mode
Posted: Thu Dec 18, 2025 10:30 am
TLDR: Please make game.auto_save() work in replay mode.
As you know, it is not possible to "seek" in a replay, to jump to a specific point in time. If you want to see the game state of a replay at the 4 hour mark, you have to let the replay run for 4 ingame hours... Hence speedrunners will use a hacky Windows autohotkey script to "press the keys" to pause the game, open the menu, and take a save every 2 minutes or whatever, while a replay is running. This is fragile and slow - you can't reliably adjust game speed too high, and you can't use the computer while it is running.
There are scripts to generate timelapses from replay, by modifying the control.lua inside the savegame's zip file (example: https://gist.github.com/Bilka2/579ec217 ... 23f2fd71a3). I tried using a modified version of that:
local TICKS_PER_SAVE = 2 * 60 * 60 -- 2 minutes * 60 seconds * 60 ticks
script.on_nth_tick(TICKS_PER_SAVE, function(event)
local index = math.floor(event.tick / TICKS_PER_SAVE)
local name = "replay_" .. string.format("%06d", index) .. "_tick_" .. event.tick
game.auto_save(name)
end)
However, the code does nothing. Adding a debug print, I know it is called. So Factorio is just ignoring calls to game.auto_save() while in replay mode - which is not totally unexpected in hindsight.
It would be super convenient, and likely not hard to implement for you devs, to make game.auto_save() work in replay mode. Perhaps add an optional default false work_inside_replay=false parameter to https://lua-api.factorio.com/latest/cla ... #auto_save . Since it is already possible to manually pause the replay to take a save, it should not desync the game state to do so.
As you know, it is not possible to "seek" in a replay, to jump to a specific point in time. If you want to see the game state of a replay at the 4 hour mark, you have to let the replay run for 4 ingame hours... Hence speedrunners will use a hacky Windows autohotkey script to "press the keys" to pause the game, open the menu, and take a save every 2 minutes or whatever, while a replay is running. This is fragile and slow - you can't reliably adjust game speed too high, and you can't use the computer while it is running.
There are scripts to generate timelapses from replay, by modifying the control.lua inside the savegame's zip file (example: https://gist.github.com/Bilka2/579ec217 ... 23f2fd71a3). I tried using a modified version of that:
local TICKS_PER_SAVE = 2 * 60 * 60 -- 2 minutes * 60 seconds * 60 ticks
script.on_nth_tick(TICKS_PER_SAVE, function(event)
local index = math.floor(event.tick / TICKS_PER_SAVE)
local name = "replay_" .. string.format("%06d", index) .. "_tick_" .. event.tick
game.auto_save(name)
end)
However, the code does nothing. Adding a debug print, I know it is called. So Factorio is just ignoring calls to game.auto_save() while in replay mode - which is not totally unexpected in hindsight.
It would be super convenient, and likely not hard to implement for you devs, to make game.auto_save() work in replay mode. Perhaps add an optional default false work_inside_replay=false parameter to https://lua-api.factorio.com/latest/cla ... #auto_save . Since it is already possible to manually pause the replay to take a save, it should not desync the game state to do so.