How do I use Array with LocalStorage

Get help using Construct 2

Post » Mon Jan 11, 2016 4:46 pm

I've 50 buttons, each one for a specific level. Ath the beggining of the game, these buttons are set with 50% of opacity and they are disable. When the player finishs the level, if he/she wins, the button's opacity changes to 100% and its frame to different one that show a specific badge, in according with a variable that store the points. Before to use badges, I was using local storage to store the "lock/unlock" variable. But with the badges (3 in total) I know that I need to use an array. The problem is that I never used an array with local storage. Can someone help me with this issue? Thanks in advance.
B
72
S
13
G
2
Posts: 989
Reputation: 6,969

Post » Mon Jan 11, 2016 5:23 pm

You can use the Array object's AsJSON expression to get the contents of the array as a JSON string, which you can then put into local storage. When loading, use the Array object's Load action to load the array from the stored JSON string.
Moderator
B
113
S
41
G
20
Posts: 1,586
Reputation: 19,096

Post » Mon Jan 11, 2016 5:52 pm

linkman2004 wrote:You can use the Array object's AsJSON expression to get the contents of the array as a JSON string, which you can then put into local storage. When loading, use the Array object's Load action to load the array from the stored JSON string.


I don't know much of arrays and Json. I don't imagine how to prepare the array for this situation and how to save the informations of the each button in the arrays and in the local storage after and how to load and show the right buttons frames. I need more detailed informations, if is possible, but, thanks anyway.
B
72
S
13
G
2
Posts: 989
Reputation: 6,969

Post » Mon Jan 11, 2016 5:55 pm

There are multiple tutorials on how to use arrays and many examples in the forum..
The saving part is done as described above..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon Jan 11, 2016 9:39 pm

@linkman2004

I create the key and set it to array.asJson. Now, I'm trying to use Localstorage.itemValue("array_key") do load Json and I can't. Do you know where is the problem? Thanks in advance.
B
72
S
13
G
2
Posts: 989
Reputation: 6,969

Post » Mon Jan 11, 2016 9:47 pm

Without seeing your events I can only guess..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon Jan 11, 2016 11:01 pm

LittleStain is right -- you'll need to post either a screenshot of your events, or a link to your CAPX.
Moderator
B
113
S
41
G
20
Posts: 1,586
Reputation: 19,096

Post » Tue Mar 28, 2017 3:24 pm

RBuster wrote:@linkman2004

I create the key and set it to array.asJson. Now, I'm trying to use Localstorage.itemValue("array_key") do load Json and I can't. Do you know where is the problem? Thanks in advance.


It's a shame this never got answered.

I too am wondering what JSON string I need to tell the array to load. The only thing I can enter is 'LocalStorage.Key' but it will not let me specify which key.
- Head of Tall Story Studios.

Creator of GOV, Project Abyss, Spiritlands & more!
B
27
S
12
G
1
Posts: 124
Reputation: 3,044

Post » Tue Mar 28, 2017 6:17 pm

- Head of Tall Story Studios.

Creator of GOV, Project Abyss, Spiritlands & more!
B
27
S
12
G
1
Posts: 124
Reputation: 3,044


Return to How do I....?

Who is online

Users browsing this forum: SoldjahBoy, Yahoo [Bot] and 9 guests