How Do I Save the Game Progress?

Get help using Construct 2

Post » Mon Dec 31, 2012 2:41 am

Dear Friends,

I am very new to Construct 2 and learning from the tutorials available. Anyways, my question is, what can i do to save the progress of the game if its being played on browser and most importantly on a mobile device, like iOS / Android based.

Means if there are 10 levels/stages of a game and a user has cleared 3 level/stages. Now what can i do that even if the user closes the game in his mobile device and re-opens he could resume the game from level 4 and so on.

For example if you are playing Angry Birds, there is always first stage unlocked and once we clear we unlock the next as well as it saves the progress that if we close the game next time we continue from where we left off.

Hope my question is clear, really looking forward for help and support.

Regards
Hamood Mehmood
B
5
Posts: 13
Reputation: 401

Post » Mon Dec 31, 2012 12:17 pm

Look into the WebStorage Object. Haven't played with it at all but after a quick glance, it stores session values so should be ideal for you.
B
15
S
5
G
7
Posts: 877
Reputation: 5,650

Post » Mon Dec 31, 2012 6:17 pm

Hey thank you for your reply, yes i did tumbled upon the webstorage but i am not sure if it will work on the mobile devices, thats why i posted the question in here...... but hey thanks for the heads maybe i'll search on it bit more...
B
5
Posts: 13
Reputation: 401

Post » Mon Dec 31, 2012 6:28 pm

Should work using local storage in the WebStorage object. Hopefully someone can clarify that.
B
15
S
5
G
7
Posts: 877
Reputation: 5,650

Post » Mon Dec 31, 2012 6:42 pm

Works for mobile ! Just search for a tutorial on how to use it ...
B
35
S
16
G
16
Posts: 2,222
Reputation: 16,589

Post » Mon Dec 31, 2012 7:02 pm

save:



SCORE gets saved to a cookie holding the key "HighScore".

load:



for further information
B
8
S
2
Posts: 110
Reputation: 1,463

Post » Mon Dec 31, 2012 10:15 pm

Astrosus you are awesome, thanks a million, @ WhiteClaws and Procrastinator thank alot for your input as well....

Just one more thing again friends, can i use this webstorage plugin to save game progress as well, as i mentioned in the original post that if we have 10 stages/levels and player has cleared 3 stages/levels, next time when he plays the game it continues from same point, just like in angry birds game.

I am working on a game and i dont know how to achieve it, my focus is mostly mobile devices, thanking you all in anticipation. Am sure you guys will help me out just can't wait lol.

Regards
Hamood
B
5
Posts: 13
Reputation: 401

Post » Mon Dec 31, 2012 10:39 pm

Set local key "LevelReached" to CurrentLevel

then in start of layout, CurrentLevel = local key "LevelReached"
B
15
S
5
G
7
Posts: 877
Reputation: 5,650

Post » Mon Dec 31, 2012 10:51 pm

Dear Procrastinator,

Thank you so much for your quick reply, but am not sure if i know how to use this, am sorry its not even been a week of C2 for me so my grasping of tips is quite old school.

Could you kindly make a kinda step by step thing or maybe a lil CapX, file that saves the progress of levels, I think its too much to ask, but friends whatever suits you, I'll be highly grateful.

Regards
Hamood
B
5
Posts: 13
Reputation: 401

Post » Tue Jan 01, 2013 12:35 am

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.
Savvy001Savvy0012013-01-01 00:56:58
B
56
S
20
G
13
Posts: 778
Reputation: 13,204

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 20 guests