How do I save highscore list?

Get help using Construct 2

Post » Sun Apr 16, 2017 11:37 pm

Hello everyone.

I created a top ten highscore layout using arrays. Now my problem is that every time I leave the game on my phone the entire list is gone.

I tried to use local storage to achieve that but it didn't work. I used "Set Array to Array". Then when I enter the layout with the scores I've done "On start of layout - Set "Array" to Localstorage.itemvalue"

Does anyboday have an idea?
B
14
S
2
Posts: 48
Reputation: 753

Post » Mon Apr 17, 2017 12:12 am

Question: Are you saving as a JSON string?
B
15
S
6
G
5
Posts: 30
Reputation: 3,652

Post » Mon Apr 17, 2017 12:30 am

Yasharitsu wrote:I tried to use local storage to achieve that but it didn't work. I used "Set Array to Array". Then when I enter the layout with the scores I've done "On start of layout - Set "Array" to Localstorage.itemvalue"


Here is how I save and load an array:

The save event (lets say click "save" button) triggers the following actions to save High Scores array (we'll call this "hscore":
Object Local Storage: Set item "hscore_key" to hscore.AsJSON

On Layout Start:
Object Local Storage On item "hscore_key" exists: Get item "hscore_key"

Object Local Storage on item "hscore_key" get: Object hscore (the array) Load from JSON string LocalStorage.ItemValue
B
15
S
6
G
5
Posts: 30
Reputation: 3,652

Post » Mon Apr 17, 2017 10:05 pm

GOObGONE wrote:
Yasharitsu wrote:I tried to use local storage to achieve that but it didn't work. I used "Set Array to Array". Then when I enter the layout with the scores I've done "On start of layout - Set "Array" to Localstorage.itemvalue"


Here is how I save and load an array:

The save event (lets say click "save" button) triggers the following actions to save High Scores array (we'll call this "hscore":
Object Local Storage: Set item "hscore_key" to hscore.AsJSON

On Layout Start:
Object Local Storage On item "hscore_key" exists: Get item "hscore_key"

Object Local Storage on item "hscore_key" get: Object hscore (the array) Load from JSON string LocalStorage.ItemValue


I'll have to test this on my phone. It doesn't work in the construct 2 preview but I think it doesn't save any game progress and deletes everything after I close the browser.
B
14
S
2
Posts: 48
Reputation: 753

Post » Mon Apr 17, 2017 11:42 pm

Yasharitsu wrote:I'll have to test this on my phone. It doesn't work in the construct 2 preview but I think it doesn't save any game progress and deletes everything after I close the browser.


Interesting, I haven't tested it on mobile so sorry I can't help you from here. Hopefully someone with more mobile experience will chime in soon.
B
15
S
6
G
5
Posts: 30
Reputation: 3,652

Post » Wed Apr 19, 2017 3:55 pm

GOObGONE wrote:
Yasharitsu wrote:I'll have to test this on my phone. It doesn't work in the construct 2 preview but I think it doesn't save any game progress and deletes everything after I close the browser.


Interesting, I haven't tested it on mobile so sorry I can't help you from here. Hopefully someone with more mobile experience will chime in soon.


Didn't work. I probably did something wrong.
B
14
S
2
Posts: 48
Reputation: 753


Return to How do I....?

Who is online

Users browsing this forum: JaredX and 12 guests