[Solved] Show total time at end of level on "You Won" screen?

OK. I just tried to do that, and got totally confused. Are you saying that once the end of the level is triggered, set global variable GlobalTimeSinceStart to another global variable called TimeSinceStart()

Hi TimeSinceStart() is a function to return the calculated value of the elapsed time since the scene start so assign to the variable GlobalTimeSinceStart the function TimeSinceStart()
And for the previous if you do what I say above and save into Storage the time for each level you play then you can retrieve from Storage and put the leveltime into any scene variable then show that value in a text object like

Read “leveltime_1” from storage “save” assign to prevleveltime
MyPreviousLevelText = Modify text to "Previous level time: " + prevleveltime

Sorry, my bad. It’s not TimeSinceStart(), it’s TimeFromStart().

Then I’d recommend using a global structure variable (for those reading this thinking “use an array”, my argument is that arrays are zero indexed, whereas levels start at 1, so it keeps things simple). Say it’s called LevelTimes :

Then at the end of the level, use these events to update or add a time (replace the 1 with the level number) :

You then can save the global variable into storage (JSONify it first) if you want the times to persist after the game has been closed.

What does that mean?

@MrMen and @UlisesFreitas Are you both telling me to do the same thing? It seems like you are each telling me something different. Now I am more confused than I was a few days ago.

To try and keep the different things more clear, I’m calling the global variable “Gtime”, that will hold the time it took on the level and for recalling it on the “you win” scene.

If you don’t mind explaining again using that it would keep things much more clear. When I read things like, GlobalTimeSinceStart the function TimeSinceStart() I get completely lost.

I think I did that, but it did not show in minutes and seconds.

To JSONify is to convert it to a JSON formatted text. It’s an international standard format.

To do this in GDevelop and save it in storage, use :


To read it from storage and save it in a global variable, it’s a two step process (load into a scene variable string, then convert to global structure. Use :


Kind of. We’re both recommending you use storage to save the level times.

But I’m suggesting you use a structure to hold all the level times. For me, it’s a simpler way - you can modify the times in the structure easily, and save it when you’re done. If you want to display all the level times on the screen, it’s the easier way to do it.

@UlisesFreitas is suggesting writing each time to storage as individual entries. This needs to be done at the end of each level, and ensures that level’s time is saved at that point.

1 Like

I don’t want to display all the level times at the same time. Is that what you mean here:

I just want to show the best time for the previous level when the player beats that level.

Yes, I was thinking in cases like displaying them on a level selection screen, or a best times screen.

But if you don’t wan to do that, then following @UlisesFreitas will be less difficult. As you’re not familiar with variables, throwing global structures at you is a jump in the deep end.

I’m already mentally feeling like I’m way under the water in the deep end, so yeah… :frowning:

At one point I had it working but not formatted correctly, and now I don’t even remember how I had it working at all.

It’s a rabbit hole :slight_smile:

It was working, but just for that level. As soon as you changed scene, the time was lost.

What you essentially want to do is store the time, and recall it when needed, independent of the scene that requires it, formatting it using timeformatter::SecondsToHHMMSS(...).

Here is what I have for the playing scene I want to keep track of the time for.

timer part1
The above is in the “at beginning of scene”.

Then once the completion of the game play is concluded I have the following:

timer part1b

And then for the “you won” scene that I want to show the finished time of the previous level:

Right now nothing shows up where the time should show up on the “you won” scene.
And I still need to understand how to have on that same screen, a "Your best time: " as well.

If you don’t mind helping me a bit more, can you please explain what I’m doing wrong, using the names I’m using or I’m going to keep being confused.

You’re writing to storage named “save”, but reading from storage named “time_level_1”.

I tried switching them, but it still didn’t work.

Have you run your game to the point where you complete a level and got the “you won” scene up?

Because if you haven’t run it through yet, and there is no time saved for level 1, then when you read it in it’ll be empty, and GDevelop will use 0 as the default.

If you have run it through and completed the level, can you start the game again, and then press ctrl + shift+ i, and click on the Applications tab of the panel that appears from the right. There should be an entry under the Key column named “GDJS_save”. What is the value of it (or provide a screen shot of it)?


I couldn’t find a column labeled “Key”.

Expand local storage (that’s roughly in the middle of your screen shot) and click on "file:// "

(I forgot to include in the instructions before because mine defaults to that)

GDJS_ just shows {}

I assume that means It’s not saving correctly

I should maybe be more specific - is that since you’ve changed the events to save to storage “save”?

And what are the events around the level complete where you save to storage? Can you screen shot it?


When you write to storage, are you writing a value or a text? It should be value. You’ll need to double click on the “write to storage” event action to see which one it is.