Hey Hamood
Look at it like this.
The webstorage has 2 different methods of saving your data in the browser.
1 = Session
This one only exists as long as the player has the tab opened in the browser.
Closing the browser = finito, adios amigo, no more save game.
2 = Local
This one saves as a local cookie.
Meaning that the next time the browser is started again "and" the player starts the game, he/she can collect the data back into the game from that local cookie.
So for savegames u need local storage.
Know however that the standard MB limit of local webstorage cookies is at 5 MB.
This 5 MB limit is browser dependant, and the browser can ask the player if he/she wants to exceed this limit to a larger amount.
Now, to understand how to save "any" data u simply need to understand the code that Astrosus allready gave to u.
Once u understand his "2 event" code, the last quest is to know what to use for building a propper save game.
Thats where variables come in.
You can create "Global" variables in the event editor, by right clicking the mouse and selecting add global variable.
See these Global Variables as your data house where u collect the progress of the game.
Besides the Global Variables u can also create variables straight into the sprites themselves.
These are called "instance variables".
To do that u select a sprite, and on the left side of the screen above the "add" behaviour option is the add instance variable option.
Now, im only going to explain by using global variables, but the trick works for any variable.
Example. (all done in the event editor)
First add a Global Variable named: Hits
After that, create an event where the player hits the enemy with a projectile.
Event: Projectile colides with Enemy = Add 1 to Global Variable "Hit"
This is the basics.
Then using the code Astrosus gave u, u can save this "Hit" Variable to the local webstorage.
Create Event.
Event: Mouse left click on save button = webstorage.setlocalvalue("hit" & Hit)
Now u look at ("hit" & Hit) and probably go... huh?
The first word hit between the quotation marks is the name of the saved data. ("hit")
The second (& Hit) is the Global Variable you want to put as a value under the name "hit".
So if u have hit the enemy 2 times the data "within" the local webstorage would be ("hit" = 2).
But we save it as webstorage.setlocalvalue("hit" & Hit)
So now u hopefully understand that the, (& Hit) points tot the Global Variable named Hit.
Retrieving the saved data is as simple as setting a event on start.
Or choose a load button.
Event: When mouse click on Load Button = Set Global Variable "Hit" to webstorage.localvalue("hit")
Then Construct2 loads the saved data that is saved under the name "hit" into the Gloabal Variable named Hit.
Repeat this for all things u want to be saved and your done.
So if u want levels to be saved, then Global Variables are the way for u, as they reach across the boundaries of levels.
Meaning that a Gloabal Variable set to 2, = 2 for as long as the game runs.
U can tell the game to save each level progress as, Add 1 to Global Variable "Level"
Then putting it into the local webstorage.
Retrieving it later when load button is pressed.
And then have the Layout number set to the Global variable.
Boom, there u have it.
Hope this helps and that i spoke clearly.
Kind Regards.
Savvy001