(Solved) How to save, load and continue timer?

How do I…

Save, load & resume timer if the player chooses to continue last save? The game should also have an option to start a new save, in which case the timer should reset.

What is the expected result

The game has a stopwatch that tracks how long it has taken to complete the game. The timer should stop & save the value when game gets closed and then load the previous value & resume when the game is opened again and the player continues playing the last save. The timer should reset when the player chooses to start a new save.

What is the actual result

It looks like the time is saved in a variable, but resets when I re-open the game.

Related screenshots

Setting the variable GameSpeedrunTime in the beginning doesn’t matter because you are then resetting it to the value of “Timer” which starts from 0.

I don’t think there is a way to modify the value of a timer directly, so what I would do is have a separate variable like “SavedTime” to keep the previous time. Then you can add SavedTime to the current time value to get the total.

Thank you for a good suggestion. Unfortunately I still can’t get it to work. I think I’m doing something fundamentally wrong, but can’t figure out how to do it properly. The timer either resets when I continue from the save file or gets the correct value but doesn’t start counting again.

I tried to add what you suggested, is this what you meant?

Timers are generally ephemeral (non-permanent).

You will not be able to load a timer. If you are needing a more permanent timer or the ability to load/save the current value, just use a global variable that you add TimeDelta() to every frame. That will operate similar to a title.

No, they should only be added together when displaying or calculating the total. You are manually overwriting the variable in this line in the Timer events:

change the variable Game.speedrunTime: set to TimerElapsedTime(“Timer”)

1 Like

Thank you for the help! I already got it working. It included your suggestion, but the solution required a bit more complicated approach for my game.