How do I save scores?

Get help using Construct 2

Post » Sat Apr 18, 2015 8:24 am

Hi, im developing a mobile game with 40 levels. I want to save all the best scores for each level and display them on the menu. I watched several tutorials on the internet, in every tutotrial people are using something called webstorage but in my version of construct 2 (202) instead of webstorage, i have localstorage. I tired using same the codes used in the tutorials (system-on start of layout; webstorage - set text to webstorage.localvalue("parameter")) but it isn't working for my localstorage object. Acutally the codes are different for the localstorage object.

Please help me with this.
B
24
S
7
Posts: 337
Reputation: 2,224

Post » Sat Apr 18, 2015 8:37 am

Hi,
This is exactly what my Game Template 7 is doing ;)
You can check it out here: https://www.scirra.com/store/royalty-fr ... ection-885

It saves the highest score for each level and shows it on the levelselection screen.

Regards
Andreas
Image Image iTunes: Match3 | Google Play: Match3
B
107
S
39
G
31
Posts: 1,173
Reputation: 29,260

Post » Sat Apr 18, 2015 8:39 am

Because localstorage is a-synchronous you must first use the "get item" action and have an "on item get" event.

New beta features aren't really well-documented untill they are implemented in the stable release.
At that time there will be a an entry in the manual.
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 » Sat Apr 18, 2015 8:43 am

Oh tnx...i'll try that.
B
24
S
7
Posts: 337
Reputation: 2,224

Post » Sat Apr 18, 2015 8:45 am

Local storage is currently in beta, and thus no tutorials/manuals etc are available yet.

Relying on its current workings, would not be wise as it is likely to change bits and pieces before a stable release.

@scirra perhaps you should have waited with removing the webstorage as an option till local storage has a manual and some tutorials.

I can see a lot more of these topics popping up.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,592

Post » Sat Apr 18, 2015 10:55 am

Ok, i just got mail from scirra regarding update of a new version. So i installed it. Now i'm not understanding how to use the new LocalStorage object.
B
24
S
7
Posts: 337
Reputation: 2,224

Post » Sat Apr 18, 2015 11:06 am

Looks pretty straightforward..

to save something use the action:
Localstorage - set item "" to ""

to load something use the action:
Localstorage - get item

to use the loaded item you will have to add an event:
localstorage on item get - and add your action

the action could be something like : set global variable to LocalStorage.ItemValue
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 » Sat Apr 18, 2015 11:40 am

I'll tell you my scenario. I created a global variable called 'Score' to display score on each level. I want that score value to be saved and displayed in another layout (Menu) where user can see all his/her scores of all the levels.

As soon as the user completes a level, the score value should be recorded and showed on Menu. So that whenever user goes to that menu he/she should able see their scores.
B
24
S
7
Posts: 337
Reputation: 2,224

Post » Sat Apr 18, 2015 11:56 am

Well then it should amount to something like this:

In the level event-sheet:
on level1 completed (this is not an official event, but I'm sure you have an event taking place at this time)
> localstorage - set item "level1Score" to Score

in the menu event-sheet:
on start of layout
> localstorage get item "level1score"

localstorage on item get "level1score"
> set text = localstorage.value
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 » Sat Apr 18, 2015 4:27 pm

Wow, Thanks a lot. Its working.
B
24
S
7
Posts: 337
Reputation: 2,224

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 5 guests