How Do I Save the Game Progress?

0 favourites
  • 15 posts
From the Asset Store
Progress\Loading Bar. Now Load you game like a Professional.
  • 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

  • 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.

  • 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...

  • Should work using local storage in the WebStorage object. Hopefully someone can clarify that.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Works for mobile ! Just search for a tutorial on how to use it ...

  • save:

    <img src="http://www.scirra.com/images/articles/webStore.png" border="0">

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

    load:

    <img src="http://www.scirra.com/images/articles/webRetr.png" border="0">

    for further information

  • 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

  • Set local key "LevelReached" to CurrentLevel

    then in start of layout, CurrentLevel = local key "LevelReached"

  • 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

  • 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

  • Procrastinator and Savvy thanks a million... now i just need to apply it to my project.... and will get back to u guys if i need further help which am sure i will .... thanks once again for kind help...

  • Hello. I can't download it - dl.dropbox.com/u/666574/webstorage%20jump%20to%20level.capx

    very much it is necessary

  • MozG the link that is provided by procrastinator is working even the link that u have pasted in your comment is also working. Then whats wrong my friend.

  • I was in a stupor it, everything works. :)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)