Save the game and respawn from last level

hey everyone …
I wanna make a save point not a checkpoint I want it to save so if the game closed and opened the player respawn in the save point from last level
i’ve been searching but all the guides in youtube with old ver plz help

1 - You make global STRUCTURE variable call it MySave or something
2 - Add 2 children NUMBER var called PosX PosY
3 - Player is in collision with check/save point you set PosX and PosY vars to Player.X() and Playe.Y()
4 - Use save system from link at the bottom of this post
5 - AFTER game is launched and you load your variable from storage SET player X and Y position to PosX and PosY
6 - Enjoy

1 Like

I kept trying but idk how to work it, sorry this my first time that I’m trying to make save and load
I just want to make if the player collation from the plant will automatically saving

And on which part you encounter problems?

Cause all you want to do is fairly easy you just need to do it
So either explain or show where you get confused / stuck

here I don’t get this what should i’ll do and how
3 - Player is in collision with check/save point you set PosX and PosY vars to Player.X() and Playe.Y()
-------
and there’s no value for " Change the global variable"

thank u so much for explain i really appreciate it
but still i think made things wrong can you please check it out and help me with that

also, in every level should i copy and paste the same event and action ?

I see you don’t understand so let’s go step by step
But before that you miss here

UNDER convert json
Set player position to MySave.PosX MySave.PosY

Look you 1st saved position of player when he was colliding with checkpoint to two variables

Now when you load game you set these variables again to these values
NOW you need to change player position to these values by changing player X and Y pos to these vars
That’s all

Also you will now have problem
You see let’s say i am on level 2 i touched 3rd checkpoint and closed the game
3rd checkpoint in level 2 was at x400 and y500
Now what if i turn on game but instead of going to level 2 i go to level 1?
It will still change my pos to x400 and y500

You need to make some system so either each level have its own saves
OR reset checkpoint if i go to different level

It is fairly simply to do but depending on how exactly you want it to work what i will tell you to do will vary

So don’t just reply
Think how it should be managed

MAYBE add feature that if checkpoint is reached you still start stage as normal from start
BUT you have option to select to which checkpoint you go?
Or If i unlocked level 2 then checkpoints in level 1 are reset so only ONE checkpoint save exist for one single level exist at a time
Or like i said each level have its own checkpoints

A LOT of ways how it could be managed exist
So your only job here is to choose what approach you want to take
And maybe you have some other idea?

More detailed you describe approach you wanna take easier to me will be to give you fairy simple system that works the way you want

thank u for your time for explain all that for me

Still not saving and load I wanna cry
the game that i wanna create is all about levels and each level have a one save location they are short stages so all i want is the player respawn in the level that had player to reach

please if you can help me more show me the steps by screenshot either that i’ll get lost and confused

1st of all i need to apologize
I am very sorry but i gave you wrong events which works with old variable system

2nd of all ONE thing at a time
Because as you see we do multiple and all goes to hell
It is better to fix one thing hold it by the ass and move on to next one

So now saving itself
This project have save system but i made dedicated one called MySave
Just so you know what is used to make it work
Structure global variable MySave with PosX and PosY vars
Their value dos not matter they can be 99999 or 0 or 21106541651 you can but do not need to touch them

I don’t have checkpoints so i placed 6 sand tiles (yellow squares) on ground which will work as your checkpoints
Player is in collision with sand tile posx and posy vars are set to player x and y position and save is performed

And these are all events it uses to work
Going from top to bottom

1st at beginning of scene
IF MySaveGroup exists in MySaveStorage (meaning you saved at least once so you touched at least one checkpoint (sand in my case))
We are loading save from storage to MySaveTempSave (i just clicked add on it and it was scene number variable with value 0 which i did not change
Where i would guess it could be anything and it does not matter)
image

AFTER it is loaded in 3rd action we are changing player position to MySave PosX and Y

And finally saving itself
If player is in collision with Sand (Checkpoint)
WITH TRIGGER ONCE and trigger once is very important here
We are setting MySave.PosX and Y to Player.X() and Y
And after vars are set we perform save

Your role here is to simply replicate this into your game
Your save can be called Save and MySaveStorage and MySaveGroup can be called Storage and Group
i just named them this way for sake of this mini tutorial

Here you can test it
Just step on sand and refresh page
You will automatically be moved to sand on which you last been
Or close tab and open it again
WASD works same as arrows
After you get it to work in your game we gonna move into dealing with levels

It’s okay my friend
Thank u i’ll try it :+1:t3:
—-
Look i found this way to save and load and it worked! But I don’t know if it safe to save and it will not lost

In the one level I wrote these events☝🏼

And here in every level I wrote events like these :point_up:t3:

You were very close before. The problems are highlighted in the red boxes:

If you want to reference a variabels or function, do not enclose it in quotes. “MySave” (in quotes) is literally the letters “M”, “y”, “S”, “a”, “v” and “e”. It is not the contents of the variable MySave, but a string made up of those lettters.

If you want the value in the variables, just use the variable name without quotes.

Here’s an example, where the variable is named MySaveTempSave. It’s in the convert JSON expression without quotes, and its value will get used:

This will get tedious if you have a large number of levels, and is more error prone:


As a tip, a simpler method that can be used for an unlimited number of levels is:




To get this, click the “Use an expression” button when selecting the scene:

@MrMen
Damn i did not spot that quotation marks
I hate dyslexia

Anyway if we are going for most simple approach i wanted to go with this
These events would be used to automatically take player to last level in which checkpoint was reached and load his position
Where 1st event should be in scene from which player is taken to last level
And 2nd and 3rd events should be placed in each levels scene events

@RoyTheLegend
Just be aware MySave.Level needs to be TEXT variable

ALSO
If i unlocked level 2 and reached it checkpoint i restart game i will spawn automatically in level 2 at its checkpoint
BUT if i would be able to go back to level 1 and reached its checkpoint
Then checkpoint save would be overwritten so next time i reset game i would not spawn in level 2 checkpoint but level 1 even so level 2 was unlocked

That is why i did ask how exactly your game work
So i can adjust it to it

Like can you go to previous levels
Should each level have its own checkpoint
Should it force player to go automatically to checkpoint? Maybe you would leave choice to player does he want to start from checkpoint or from beginning of level?

A LOT of things you may want to go with in your game i don’t know about so i did not know around what make whole logic

with the way i did i used save value not a text now when i try to make text it doesn’t work

i tried you technique to save i did the same you did but here i didn’t find “CurrentSceneName()”
5

thank u for the advice
look i think here only needs a child but i didn’t tried yet idk if will works
6
7

Look here are my global variables
Notice how Level is TEXT variable
And PosX is NUMBER variable

And look for PosX i can’t type CurrentSceneName()
I mean i can write it down but expression for it DO NOT EXIST for number variables

Now check this out
When i do the same for Level which is TEXT variable what do we have as 1st option?

You most likely did not change Level to be text variable

ugh why this is so hard and not working :frowning:


that’s what i did in main menu sheet, the button not works etheir with these events even if i added Change to scene level1

and here what i wrote in the levels events

Because your logic is incorrect. You have the change scene event as a subevent of the “At the beginning of the scene” event.

A sub event is processed or actioned only if the parent is actioned. The parent only actions once at the start of the scene, so the subevent is only processed once - when the scene starts.


If you want the player to move to the saved position, you first need to load the saved position from storage. You’ve done something similar earlier, loading present level from storage. Do the same in the “At the beginning of the scene” event with the saved position.

I started using gdevelop around 2 years ago
Since that time i NEVER see Keith giving me bad advices
Read it carefully and understand what you are doing
You are almost there