Enabling scripted saves in replay mode

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
thuejk
Fast Inserter
Fast Inserter
Posts: 129
Joined: Fri Feb 13, 2015 8:41 pm
Contact:

Enabling scripted saves in replay mode

Post by thuejk »

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.
vinaghost
Burner Inserter
Burner Inserter
Posts: 6
Joined: Mon Sep 08, 2025 4:10 am
Contact:

Re: Enabling scripted saves in replay mode

Post by vinaghost »

LuaGameScript::take_screenshot has "allow_in_replay" parameter
https://lua-api.factorio.com/latest/cla ... screenshot
wspikes
Burner Inserter
Burner Inserter
Posts: 9
Joined: Fri Jun 10, 2022 4:05 pm

Re: Enabling scripted saves in replay mode

Post by wspikes »

Adding a vote in favor of this request, from the perspective of someone who runs one of those AHK scripts to splice a run.

The AHK workaround isn't that great -- it's basically a glorified sleep-loop with a few mouse clicks, along with a prayer that it works and all coordinates are correct.

Unfortunately, it doesn't work too reliably. Just last night, I was slicing a 10.5-hour run into 5-minute segments at 2x speed, and in the late stages of the run, my computer couldn't keep up at 120 UPS (replay), so instead of getting 5-minute slices, the late slices were around 3.5 minutes. Now, my options are to either rerun the slicer at 1x speed or to accept the variance.

I'd really love it if we could do a much simpler control.lua replacement of the save, so preparing these slices for analysis becomes much more reliable.
Tertius
Smart Inserter
Smart Inserter
Posts: 1499
Joined: Fri Mar 19, 2021 5:58 pm
Contact:

Re: Enabling scripted saves in replay mode

Post by Tertius »

About the save game button being moved down when the galaxy of fame unlocks: I see in your ahk you're familiar with checking the screen for pixels of some given color. There is an anchor for the save game button: it's always 3 buttons down from the top menu entry. The top menu entry is the only one that's green. So use PixelSearch to locate the top menu entry starting from slightly above the center of the game window. Use the color green for this. Then click 160 pixels down from the position it found or whatever distance for your monitor resolution/UI scaling there is between the green entry and the save game entry.

However AHK cannot detect the ups within Factorio, so it cannot adjust to the game speed. This is something that can only be managed within Factorio.
Post Reply

Return to “Modding interface requests”