How do I Load saved data?

Get help using Construct 2

Post » Thu Oct 30, 2014 9:58 am

I may be missing something here, but I am getting my game to save each levels score into an array, and then save that data as Local Web storage. Now this works when I test it on my browser and it even works when I install my app. But as soon as I quit my app and re open it all the data is not loaded, its like it was using session web storage rather than Local. Has anyone else had this problem or know where I may be going wrong? Thank you in advance.
You do not have the required permissions to view the files attached to this post.
B
7
S
1
Posts: 61
Reputation: 567

Post » Thu Oct 30, 2014 12:43 pm

Hard to tell with the little screenshot here.

But apparently, you are simply not loading the saved data when you start your application.
You set a local key named "Level" but on start of layout try to load a local key named "XBest" (where X is a number).
As far as I can tell from the screenshot, no key "XBest" exists.

Also I'm not sure starting the key name by a number is the wisest thing to do anyway.
Make sure to save "Level"X"Best" keys at the end of each levels, and then you should be able to load data from those keys afterwards.

If you are still having issues, consider posting your whole capx as it may help finding the issue easier.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
292
S
115
G
96
Posts: 7,295
Reputation: 70,795

Post » Thu Oct 30, 2014 1:20 pm

Hi Kyatric,

Appreciate the reply. The game is currently in Beta and I am not allowed to post the full .capx file am afraid.

The most confusing thing is that the code for the high scores works. My game remembers the high scores for each level, so clearly the information is being stored and recalled correctly. But as soon as I exit the app and come back they have reset.

Essentially I have a global variable called Level that starts on 1 and as a level is completed +1 is added to it. Once the level is won, the score global varible is tested to see if it is grater than the value stored in the array ( Array_Best_LevelScore ) of the same number ( Level ) if it is the new score is then saved into that slot and displayed. This is then saved as a local key level*global varible*&("Best"). If it is not grater than the array the text simply displays the current array slot value. As noted this all works when the game is running, but its like my array is not being saved......

As I have been rambling I think I see what you are getting at.... I am saving the array numbers as Local values, but I am not re loading those (levelnumber)Best local values back into the array when the game starts!! What an idiot.

Ha will give that a try thank you very much!
B
7
S
1
Posts: 61
Reputation: 567

Post » Thu Oct 30, 2014 1:34 pm

Your screenshot is a bit of a mess.
What I do is take the game out and make a small demo - get it to work then put that demo into game.

From what I see, I understand that when level > webstorage you want to set the score... but I find this isn't the best way to do it. It is essentially everytick. Game runs through eventsheet evertick and if Level>webstorage it stores it.

How do you store score to variable level? I would create a function to save to storage and put that immediately after you update score.

This does 3 things.
1) It only updates - writes to webstorage when player score changes(he could be running around for half an hour without picking up a coin - lol), and
2)removes the every tick check.
3) and you can feel all fuzzy and warm inside knowing that his score and webstorage are being updated together (which is what level>webstorage is) but this way is better. Nothing worse than a player loosing his latest score - Grrrrrr - lol
Last edited by DUTOIT on Thu Oct 30, 2014 1:36 pm, edited 1 time in total.
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,718

Post » Thu Oct 30, 2014 1:35 pm

Hey DUTOIT,

Some good tips there I will try to implement them, thank you very much for the help!
B
7
S
1
Posts: 61
Reputation: 567


Return to How do I....?

Who is online

Users browsing this forum: Google [Bot] and 36 guests