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 :
@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.
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.
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(...).
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.
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)?
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.