Local Storage Question

Just started using Construct 2? Post your questions here

Post » Fri Jul 24, 2015 4:44 pm

Hi everyone, new to Construct 2 and the forums, it's great to be here! :D

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
B
7
S
1
Posts: 12
Reputation: 530

Post » Sat Jul 25, 2015 12:24 am

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.
ImageImage
B
130
S
23
G
7
Posts: 1,078
Reputation: 13,280

Post » Sat Jul 25, 2015 9:32 am

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)! :)
B
7
S
1
Posts: 12
Reputation: 530

Post » Mon Jul 27, 2015 1:15 am

Hey again hazy, happy to help out - though sorry for the late reply! :)

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 :) with persistence I am sure you will be up to speed in no time!
ImageImage
B
130
S
23
G
7
Posts: 1,078
Reputation: 13,280

Post » Mon Jul 27, 2015 12:05 pm

Hi GenkiGenga, no worries on the timing! :D I have been glued to C2 all weekend trying to figure out the local storage feature! :shock: 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:

Image

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 :geek:

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)
B
7
S
1
Posts: 12
Reputation: 530

Post » Wed Jul 29, 2015 1:33 am

Haha, sounds like you will be a pro in no time :)

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.
ImageImage
B
130
S
23
G
7
Posts: 1,078
Reputation: 13,280

Post » Thu Jul 30, 2015 9:10 am

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! :oops:

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 :geek: :?
B
7
S
1
Posts: 12
Reputation: 530


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests