[SOLVED]A simple and efficient way to resume the game

Second: Another day, another problem :slight_smile:

The problem is this, when the character is killed I change the scene to “GameOver”. This scene from 2 options, go back to the main menu, or start the level again. The first is simple, the second how should I do it?
I could have created a layer for each level, but you will understand that on a 100-level game, it would have been unnecessarily heavy.
I thought of linking the “Resume” button with the “Start” menu button, but this leads to the problem of having to create the save for each level passed. So how do I do it?
(I think it’s the easiest and fastest method, as well as the least resource-intensive one, but if I’m wrong, I accept advice :))

Hi, this is only for resuming a scene after death.

I used variables for scene ID and at the beginning of the level scene, I set the ID number:

Change global variable Scene to Variable(sceneid)

So you’d need a global variable called Scene - leave that one empty - and then make a variable on each level named sceneID, which you would enter the level number in the value.

You’ll have to program the ‘retry’ button on your death scene for every level as well, like:

Cursor touch is on button object
Left mouse button is down
Global variable Scene = 1
Change the scene to “level1”

Let me know if you need more details. :slight_smile:

1 Like

First of all, thank you for your kind and complete answer!
But, I use Gdevelop recently, so I’d be grateful if you could show me an example (if it’s not too much trouble obviously :))

Also, I don’t understand having to reprogram, does this mean I have to create a “GameOver” scene for each level?

EDIT: I was thinking of creating a global variable to see the level at “start” pressure, and set it like this:
If it is = 0 then change the level 1 scene
If it is = 1 then change the level 2 scene
If it is = 2 then change the level 3 scene
and so on…

Completing the level increases the global variable by 1.
(then maybe I will add in the settings the “reset” button that will set the variable as 0)

Is the logic right?

1 Like

Yes, I will upload something for you soon. It should answer the third question as well :wink:

Not at all, I meant you only need to add the events for the ‘retry’ button to the one death scene. The variables will allow you to use one death scene for every level.

1 Like

Thanks a lot you are really kind! (for third question you mean EDIT?)

Ahhh … I understand! At this point, to make it more “slender” wouldn’t it be better to create an external event? (So I could use it both for the game over and for the start, and find a way to save the global variable)

You’re welcome!

When you asked if the logic was right.

Here is a very bare bones example project.

I just made it within the hour and didn’t check on your other threads to see what type of game you’re building (sorry), so used platformer behaviors. I apologize for the name of the folder too - my computer wouldn’t let me rename it (said it was in use by another program).

This is only a starting point and one way of doing it. You might find a different way or another member of the community may have other suggestions :slight_smile: Feel free to take what you can use from it and leave the rest.

Certain events related to scene variables will probably need to be included within the scene events, but that’s one line. The events I referred to in previous posts are not all for one scene.

You’ll see in my file that I used a mix of scene and external events. Usually if something would be really repetitive and stays the same across scenes, I use the external sheets.

You can use an external sheet for most of your logic though.

1 Like

Your help is a hand from heaven, I think I understand everything! THANK YOU VERY MUCH!
I only have one tip, but maybe that’s wrong, at the beginning of each level you set the global variable as “= number”. Wouldn’t it be easier to set it as “+1”?
Or would this, on repeating the level, increase the variable again? in that case, could the “once only” function serve?
Simple curiosity :slight_smile:

1 Like

You’re welcome.

I don’t think that would work as you expect.

I mean you can try it that way and see what happens, but I do think you’d end up increasing the value when it isn’t desired and trigger once won’t solve that if the scene gets restarted multiple times because the event would run again. There probably is a way to ensure that it doesn’t do that like add another condition such as, on level 2:

Global Variable Scene is = 1, add 1

On level three:
Global Variable Scene is = 2, add 1

But why do that when you can just set the value and not worry about extra events to change it?

1 Like

Yes I tried and the result is as you said :slight_smile:
Sorry if I take advantage of your kindness and availability, now I have a problem with saving the global variable. How can I save it? using the JSON file, it says that it can only save scene variables, which is strange … is there another command to use?

1 Like

No worries, although I will have to step away from the computer for a while soon.

I’m not a master at saving / storage by any means, but as far as I know, there’s no way to save to a global variable directly - you have to pass data back and forth with a scene variable.

1 Like

I understand, this is a nice limitation…
I’m making several attempts, but nothing …
However since my question has been resolved, I close this question indicating it as resolved, and create a new discussion, so that tomorrow they can be useful for other users :slight_smile:

Thanks so much for your valuable help! If you want to answer the other discussion, of course, you are more than welcome! :slight_smile:

1 Like

I might have simplified it a bit more in this upload and was able to rename it too :grin:

1 Like

By putting everything in the “gameplay” the game in addition to becoming lighter in weight, it also becomes faster in use, right?
Or is taking an external event expensive in resources?
Unfortunately I don’t find a documentation on these things, in my opinion very important :frowning:
Thanks for sharing this improvement anyway!

1 Like

There’s this page about debugging poor performance, but it doesn’t mention external sheets being expensive. In the file, the main thing is that you can now update the global variable with the scene ID variable; it automatically takes the ID# from the current scene VS you having to specify it on every scene (except in the scene properties > variables). Ultimately, it’s less redundant events. :slightly_smiling_face:

1 Like

thank you very much! now I get it!

1 Like

Good converstaion i was very happy and i learn how to change scenes

1 Like