Local Storage Question

0 favourites
  • 7 posts
From the Asset Store
Basic Plugins for Firebase Authentication, Realtime-Database, Firestore, Cloud Storage
  • Hi everyone, new to Construct 2 and the forums, it's great to be here!

    I have a question about the Local Storage option in Construct 2, I'm currently using the System load/save feature to record/save the game data but when this method is in use it is limited and relying on the user to manually click the save or load buttons within the game itself. Is there a method that can auto-save the game play as the user progresses without them having to manually click save? I am also concerned about the fact that some players may just x off the browser also, thus losing data. I have read many tutorials over the past couple of weeks, thank you inadvance to all contributors, I would not know as much as I do now only for the members taking the time to share their knowledge! I am sorry if I missed a tutorial on this, I have found some webstorage tutorials but my exposure to Construct 2 is quite limited now in terms of experience so I am not sure how to transfer that knowledge to the new local storage option. All help or advice greatly appreciated.

    Thanks,

    Hazy

  • Hey hazy,

    You could have the game save as you progressed either way. You just need to have a trigger somewhere in your game and you can make it automatic. For example, I assume your logic is "on save button pressed" -> Save game state.

    You just need to find an appropriate trigger like "When player collides with object" -> Save or "On start of layout" -> Save.

    If you are going to be saving continuously during gameplay then local storage is your best bet because saving the whole game state can cause a little freeze if you have a lot going on at the time.

  • Hi GenkiGenga, thanks very much for your prompt reply! Yes, I am using the buttons as the load/save triggers, I did originally use the System - On Start of Layout - Save option at first but then after a refresh of the browser I thought oh, how do I get the game to now load what's just been saved. So I'm not sure how to do that, I tried the System - On end of layout - Load but I believe I may have conflicts with the save feature and it doesn't seem to work. I'm sure I am missing something really obvious!

    With regard to having levels on a game - I am wondering if the System - Save is an ideal solution for this, I am assuming it will save the last "live view" for the player rather than remembering the levels they have just unlocked? So many newbie questions, sorry for this! (i have read your tutorial, thanks for sharing your knowledge, really helps us newbies)!

  • Hey again hazy, happy to help out - though sorry for the late reply! <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    So you have some different options when it comes to saving.

    The simplest of which is saving the full state of the game. You are right it's like taking a picture, everything you have done up to that point will be saved. To then load the saved game you just need to create a button (or have any kind of condition really) that when pushed will then load the full state of the game.

    Here is an example of how it works: https://db.tt/JlXb06XH

    Depending on your game this method might be acceptable, but if not then you should look into local storage (which saves specific things instead of the whole game state - like a global variable that could represent the stage number for example). There should be some tutorials up that cover local storage in more detail. I remember being a newbie too <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile"> with persistence I am sure you will be up to speed in no time!

  • Hi GenkiGenga, no worries on the timing! Thank you very much for taking the time to create and post the example, your method is what I had at the outset but I found that I am limited to users sticking with one browser (Ref: ) and also knowing when to click continue or play a new game (silly I know but I want to keep it as simple as possible i.e when a user clicks play - action will either load the previous save state from local storage or if missing load a new game)

    I have read and re-read a bunch of tutorials/references on web-storage and found a few mentions of local storage and this is what I have learned so far:

    I think i understand the logic of it now but I'm still missing something. Thank you for your encouragement!

    Gosh, just saw that I dont have enough reps to post my image - here is the image in text form

    This is on my Level Layout

    Global variable SaveGame = 0

    System - Start of Layout - LocalStorage - Check items "SaveGame_key" exists

    LocalStorage - On Item "SaveGame_key" exists - LocalStorage - Get item "SaveGame_key"

    LocalStorage - On item "SaveGame_key" get - System - Set SaveGame to LocalStorage.ItemValue

    LocalStorage - On item "SaveGame_key" missing - LocalStorage - Set item "SaveGame_key" to "SaveGame"

    This is on my Start Game layout:

    Mouse - On Left button Clicked on play button (which is a sprite) - LocalStorage - Get Item "SaveGame_key"

    then another action on this too System - Go to Levels (level layout)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Haha, sounds like you will be a pro in no time <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    Without seeing your cap.x it is hard to troubleshoot but I just had a look on the site and this is a good tutorial by AndreasR that you can follow : https://www.scirra.com/tutorials/1461/h ... age-plugin

    Check over the manual while you are logged in and you will rack up some more rep in no time, I think you need about 300 to post links.

  • Baby steps for me right now but very thankful for all the help and tutorials I have found on the site/forums!

    Yes I have read AndreasR's tutorial and it has helped me learn and understand the local storage a lot more! (thankful) I believe I may have an issue with my triggers or perhaps a conflict as this should now be solved at this point - I am going to create a new project capx this morning and take it from there, then try and troubleshoot the other game - hopefully I will have some more rep points and be able to add in the capx file soon so you might have a peek and see my crude attempt at a game!

    I am suprised I have not crashed the servers with all the running around I have been doing in the tutorials and manual at this point! But great to have a source to refer to for help! So far this is my first bump in the road but I am sure there will be more

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