How do I save and load game settings?

Get help using Construct 2

Post » Fri Oct 16, 2015 10:32 pm

I stored the game settings on an array, now i wish to know how can i save this data in a local storage and retrieve this data when the game restart? Also how can i to populate the settings with the retrieved data?

It is just 7 settings that can be changed by the user, so i've used an array (6,1,1).

I used
>local storage -- set items "Settings" to array.AsJSON (to save the data)

and

>On item "Settings" exists -- array load from JSON string "Settings" (to load the data)

but it is not working...what i'm missing?

Thanks!
B
14
S
5
Posts: 110
Reputation: 1,338

Post » Sat Oct 17, 2015 8:57 am

Hi,
You have to perform a "Check item exists" before the "On item exists will be triggered.
So add an aciton on the start of the layout "Check "Settings" exists".
If so, it will be loaded from the LocalStorage, if not, then not.

Regards
Image Image iTunes: Match3 | Google Play: Match3
B
100
S
35
G
30
Posts: 1,136
Reputation: 28,085

Post » Sat Oct 17, 2015 8:43 pm

AndreasR,

Thank you!

I've added the "Check item exist" before the "On item exist..." but it still not working. Using the debug i can see the local storage with the correct values stored, even if i restart the game without changing anything, but i can't use the values for some odd reason that i don't understand. The array still empty, when it is supposed to be filled with the values. But the fact the array is empty, is just a clue that something isn't working. I've tried to get the values directly from the local storage, without worrying to fill the array with them, like this:

>Music volume(slider) -- set value to int(local storage.KeyAt(3)) [3 is the position where the value is stored]

but this also not working. It always give me "0" even if the localstorage shows me the correct value.

I really don't know what to do now...
B
14
S
5
Posts: 110
Reputation: 1,338

Post » Sat Oct 17, 2015 8:57 pm

artbava wrote:>On item "Settings" exists -- array load from JSON string "Settings" (to load the data)

but it is not working...what i'm missing?

On item "settings" get.....Array load from JSON string LocalStorage.ItemValue

sliders.capx
B
66
S
24
G
7
Posts: 1,514
Reputation: 11,039

Post » Sat Oct 17, 2015 10:26 pm

Korbaach,

Thank you very much!

One day I would like to have this ability to understand the C2. Awsome work!

Regards!
B
14
S
5
Posts: 110
Reputation: 1,338


Return to How do I....?

Who is online

Users browsing this forum: Artcadev, Blendi1223, Yahoo [Bot] and 50 guests