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

Thanks again for the help.
I tried to implement your instructions, but I failed. I even watched a video on how to save, but still didn’t get it to work. Here is what I have in the playing scene:

And this is what I have in the “completed level” scene:

Can you tell from those screen shots what I did wrong?

In the action that reads in the value from storage, you’ve added parenthesis after the variable name. Remove them.

Thanks, I did what you said, but it still isn’t working.

Any other thoughts?

In the read from storage action, you’ve got 2 double quotes before and after time_level_1. There should be only one double quotes on each end of the name.

I had it like that because of the following error I got without double quotation marks.

timer part2

But when I did as you said, it looks like it is working now, so thank you! Any idea why I get that error message?

I also want to format the time to read as minutes and seconds, but right now it is just doing seconds followed by a decimal point followed by over a dozen digits.
I am using the TimeFormatter extension to display the time during the game level that way. How do I do that for the “you beat the level” scene? In the game play level I use "Time: " +TimeFormatter::SecondsToHHMMSS(TimeFromStart())

But when I use that on the “you won” scene, it just shows 00:00

No, sorry. I’ve had this type of thing occur on the odd occasion too, usually when I’ve made an error and correct it. In cases like that, I get focus away from the error, and then open it up again; this usually seems to fix it.

That’s because TimeFromStart() is taken from the when the scene began :

I understand that. But how do I format the text as minutes and seconds, not just seconds?

With the timeformatter::SecondsToHHMMSS(). It’s showing 00:00 because no time has passed since the “you won” scene started at the point that you set the text.

You’ll need to put the value of TimeSinceStart() into a global variable when you write it to storage in the game play level , and use that global variable in your “you won” scene.

But even with a global variable, how do I get it to format into minutes and seconds, not just seconds?

Use timeformatter::SecondsToHHMMSS(GlobalVariable(GlobalTimeSinceStart)). But you’ll have to define the global variable GlobalTimeSinceStart, and then set it in the game play level.

I am totally confused. Now my timer isn’t even working in the gameplay level. I was using the timefromstart timer in the game play. Are you saying I need to use a different timer? Variables still throw me off. What am I putting in the play level to get the time of the level into the global variable?

I forgot to mention, I also want to keep track of and display the player’s best time from the previous level as well. How would I do that?

In the game play level, set the global variable GlobalTimeSinceStart to TimeSinceStart() when the level has been completed.

Then use timeformatter::SecondsToHHMMSS(GlobalVariable(GlobalTimeSinceStart)) to display the time on both that game play level scene and the “you won” scene. Remember to set the global variable before you set the text.

And that’s fine for the game play level. But you won’t be able to use that for the “you won” scene to get the time from the game play level.

No, just use the global variable to store the time value, so it can be accessed by other scenes.

A variable just stores a piece of information. When you refer to a variable, you’re using the value it represents. Global variables can be accessed by events throughout the whole project. Scene variables are only accessible by events in that scene.

Just the one previous level, or all previous levels? They have a slightly different approaches.

Thanks for the explanation. I’ll implement it right now.

I would like players to be able to go back to any level they have completed and see the best time for that level.

Each level should take a completely different amount of time than the others, so I would need to save and recall each individual level’s best time.

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