[request] capx example for LocalStorage

Get help using Construct 2

Post » Thu Jul 02, 2015 3:26 pm

I am embarrassed. I read, read and reread the lessons dedicated to the LocalStorage or Array/dictionnary and there is nothing to do, it does not work for me. This must be my brain completely allergic to this type of logic.

I managed to set a coin storage system, with great difficulty and with kindness of AndreasR. Unfortunately I also need to add an highscore system. But just by this idea, my brain is already beginning to burrow deep in my skull.

Would someone be kind enough to share a capx example that shows how a multiple values storage is set up?
Please!!!! (crying) Please... My wife left me for my brother, my children do not want to see me, I lost all my money in the last financial crisis, my english is so bad, my club foot hurts me since I can not pay treatment against cancer. Please Help!
B
7
S
1
Posts: 64
Reputation: 585

Post » Fri Jul 03, 2015 3:26 am

Okay. That was good. You could throw in, "My dog/cat won't look at me anymore."

Did you already see these two tutorials I put together?

For Dictionary ...

http://javajdk.net/tutorial/construct-2 ... -tutorial/

and for LocalStorage ...

http://javajdk.net/tutorial/localstorag ... nstruct-2/

I have a zipped capx for the LocalStorage one linked on the tutorial. I will add a zipped capx for the Dictionary one in a few minutes.
B
29
S
16
G
23
Posts: 68
Reputation: 13,723

Post » Fri Jul 03, 2015 8:57 am

In fact, my problem is that I fail all time I try to put together localstorage, variables and dictionnary/array. Values reset at layout restart.

All examples I saw until now are talking about a part of how to do a multiple value storage. I really need an example that would shows me how to do it from A to Z.

Thank you for help and by the way your tutorials are well done.
B
7
S
1
Posts: 64
Reputation: 585

Post » Fri Jul 03, 2015 10:45 am

Have a look at my blog http://myconstruct2dev.blogspot.co.uk/ which has several in the github, the best explanation of the code is probably in the asteroids post.
My tutorial through development blog is at http://myconstruct2dev.blogspot.co.uk/
B
12
S
3
Posts: 221
Reputation: 1,328

Post » Fri Jul 03, 2015 4:46 pm

I already seen your blog, but it doesn't help me much :/

I'm still stuck....

Thank you anyway.
B
7
S
1
Posts: 64
Reputation: 585

Post » Fri Jul 03, 2015 7:32 pm

Hi @norab

I guess you already have downloaded my Coin example here?
https://shatter-box.com/downloads/const ... alstorage/

It's fairly the same if you want to save a dictionary or an array in the LocalStorage. You just need to fill it by setting the value of to global variable to an x,y or/and z coordinate in the array.
Then save the array via 'AsJSON' in the LocalStorage.

I have an example for that. It's available in the store.
https://www.scirra.com/store/royalty-fr ... torage-973

This example includes code snippets showing you how to save arrays and dictionaries.

Regards
Andreas
Image Image iTunes: Match3 | Google Play: Match3
B
98
S
33
G
30
Posts: 1,124
Reputation: 27,805

Post » Sat Jul 04, 2015 1:37 am

Thank you for your suggestion AndreasR.

Maybe the best way is to show what I did, and then someone could tell me what am I doing wrong.

In the example below, I did a mutltiple value saving system with array and webstorage but I have trouble to do it with LocalStorage (my array is stored, i can see in in debug mod, but I dont know how to return it to my text object):

my test
B
7
S
1
Posts: 64
Reputation: 585

Post » Sat Jul 04, 2015 2:20 am

OK, 2 threads and some frustrated posting by you in your other thread on this subject, because no one understands your problem with local storage... However, your problem is nothing to do with the local storage, it's to do with putting a value into a variable from a retrieved save of an array (and putting that into a text object)!!

Lesson 1 - if you're stuck, provide a capx so people know what you're referring to.
Lesson 2 - if you're not sure what you're doing and you ask for help, try to understand the help you get, or see Lesson 1.

So, from your capx - you are not saving the global variables, just the array - which is ok. But you are using the global variables to update your text objects - unless you change something, the text objects and global variables will never be updated when the array json is loaded. Also, you are only updating your text object when a button is clicked, you should put that update into a function and call it when a button is clicked or if your saved data is retrieved (assuming you alter the events to save and retrieve the data you want).
A big fan of JavaScript.
B
74
S
20
G
69
Posts: 2,207
Reputation: 43,836

Post » Sat Jul 04, 2015 3:33 am

paulscottrobson wrote:Have a look at my blog http://myconstruct2dev.blogspot.co.uk/ which has several in the github, the best explanation of the code is probably in the asteroids post.


I love your blog. I spent some time playing your asteroids game today. Very nice.
B
29
S
16
G
23
Posts: 68
Reputation: 13,723

Post » Sat Jul 04, 2015 6:33 am

I checked your capx file & updated it.
Capx: https://www.dropbox.com/s/in1izt3gsorv6 ... .capx?dl=0
Image Image iTunes: Match3 | Google Play: Match3
B
98
S
33
G
30
Posts: 1,124
Reputation: 27,805

Next

Return to How do I....?

Who is online

Users browsing this forum: evillair, Exabot [Bot], LunchboxGames, NumberOne, rekjl and 15 guests