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

What you have at the beginning of the scene section I don’t have in the “playing scene”.

What commands do you have for the second scene that gets it to show the seconds?

Exactly the same as what’s in the snip. The two scenes are identical wrt events, barring the scene name.

The last image above is only on the scene where I want to show the time from the last scene, and id doesn’t contain the commands from the first 2 images above. Is that the problem?

Why are the quotes around the word time_level_1 angled, while the quotes around save are straight down?

image

I suggest you retype the quotes around time_level_1 in both the write and read actions, so that they are straight down

Because the word time_level_1 isn’t stored, but the word save is stored. So I suspect those quotes have something to do with it.

I have no idea. I just looked, and they don’t look like that now. I retyped them in anyway, and I’m still not getting it to show up on the “You win” scene.

Can you make a new, small project, like I did, and see if you can get it to save to, and retrieve from, storage?

Before I do that, I want to make sure we are both trying to do the same thing. Did you see my post about how the score needs to be displayed on a scene that is not the same as the game play scene?

The “you win” scene should display the retrieved storage value, not the game play scene.

I don’t know what I did, but it’s working now. I rebooted my computer, and reopened the file. I guess it’s possible that it was a glitch?

Now I’m going to try adding the “best time” read out. Hopefully I won’t go through all the same issues. Haha.
*Edit:

I’m trying to get the “best time so far” working, but am confused. Did the above suggestion rely on me doing the thing you said was much more involved and used Json files?

What I am trying to do is if the last time the player played this level, the level time was quicker than the current run, display that time as a separate line of text next to the current time on the next scene, the “You won” scene. If this run on this level was quicker than the past quickest time for that level, then say, “New best time!” along with the time.

So levels can be replayed any time?

For example, say there are 10 levels, and the player has reached level 8. If they then replay level 4 and complete it faster than last time, you want the message to come up with the old and new times and the message “New best time”?

Yes. Any completed levels can be replayed to try to beat the best time you have done on that specific level before.

I assume I need to compare the time saved in the “time_level_1” or “time_level_2” (etc) which ever level you go back to play. Then if the new time is < than that saved time, save “time_level_1” write new “best_time_level_1” in save. Or something like that but got very confused when trying to find the functions in GD.

I believe the best way for this is to use a structure. So, lets throw you in the deep end :grin:

  1. Create 3 global variables as below - a structure, and two numbers :

  1. In the very first scene that gets opened when your game is run (main menu, title scene or what have you) add the following event. Make sure it’s a read text from storage, :

  1. In each of your levels, add this event, and change the value for current_playing_level to whatever the level is :

  1. For the level completion event of a game play level, use the following :

  1. In the “you won” scene add :
  • a text box name CurrentTime
  • a text box named PreviousBestTime
  • a text box named NewBestTime (with text “New Best Time!”)

  1. Add the following to the “you won” scene. Make sure to use write text to storage : :

Note, I’ve used curr_level and prev_time to make it easier to read what’s happening.

The events in the last step will check if a previous time exists, and if not, add it, declare it a new best time and add the new time to storage.

I’ve tested this, and it works. If you have any issues, screen shot what you’ve done so we can help pinpoint where the issue is.

1 Like

brain-explosion

I barely made it out alive just doing the last stuff with keeping track of time. You think I can handle this? :dizzy_face:

I was debating having 3-5 stars (or something like that) that people could find in each level, but wasn’t sure how to do it. If I make it through the method you described above to track the time for each level. Will a similar method also work to keep track of how many “stars” the player collected in each level so I can show that next to the best time?

Also, should I delete all the commands that I currently have that are working just to show the time from the last level? Obviously I’ll save that version first just in case.

Yes, most certainly. Have a read through the code to understand what it does. If there’s something you’re unsure about, yell out.


Yes, start with a clean slate, so to speak. To back it up, just copy the game.json into the same drive.

What do you mean “use write text”?
I don’t see a command about writing in that screen grab.

Ah, no, that was an editing mistake. There is no writing to storage at step 4. It should be for step 6. I’ve updated the instructions to reflect this.

Not sure what I did wrong, but it’s not showing the best time.

Here is what I have for the opening title screen when the game is started:

Here’s what I have for the playing scene that I need the best time from:

Here is what I have for the “You won” scene

You’re using TimeFromStart(). You should be using Variable(prev_time)

Also, at the beginning of the “you won” scene, set the boolean variable new_best_time to false (you’re currently setting it to true)

Is this correct now? It’s still not working.

You’re reading from storage group level_times, but writing to storage group all_level_times

I believe that is what you did in the example you posted. I just looked at your screen grab, and it looks like that is what you have.

I just tried changing the “level_times” to “all_level_times”, but it didn’t fix it.