How do I Create Highscore for Autorunner?

Just started using Construct 2? Post your questions here

Post » Mon May 19, 2014 12:58 pm

I'm struggling to create a Highscore for my game. I understand that you do this through webstorage but i've had multiple attempts at this but i keep getingt different issues with it.

I'm making this game for phones and want to display the highscore on the Main Menu and Game Over screen. I also want to so that the highscore updates as soon as the score has been beaten.

Can someone help me out, i've provided a capx file that i created just so i'm under the 2mb limit to post it here.

Thanks
You do not have the required permissions to view the files attached to this post.
B
5
S
2
Posts: 116
Reputation: 867

Post » Tue May 20, 2014 12:45 am

Hi,
You can see in game layout that there is scoring in the top left corner. This text object is named DistanceDisplay. Now in the GAME EVENT you can find a line where this number changes:
http://screencloud.net/v/7kOO

So we can assume that TotalDistance is your score.

Now add Web Storage to the project so we can use it.

First we need to check if there actually is any highscore so we do this event:
http://screencloud.net/v/1kBE
It basically means "on start of the layout check if local key "MyGameNameHighscore" exists, if not then create it set it to 0.

Now during the game, we want to know if the highscore has been beaten. You can check it every tick or every x time. Just like this:
http://screencloud.net/v/hLH1
So... Every 2 seconds check if TotalDistance is greater than value stored at "MyGameNameHighscore", if yes then assign a new value to this key.

And that's it.
Now you wanted to view the highscore in the main menu?
Then try adding a event that checks if the local key exists (at the start of the layout - you did this before).
If yes, then set an object in the main menu to visible and set it's value to WebStorage.LocalValue("MyGameNameHighscore")


Let me know if you succeeded : )
B
6
G
1
Posts: 28
Reputation: 458

Post » Tue May 20, 2014 12:46 am

Btw, you dont have to create variables for toggle_sound etc. You can use Audio object to check those kind of things like "Is silent", "toggle silent" etc : )
B
6
G
1
Posts: 28
Reputation: 458

Post » Tue May 20, 2014 9:58 pm

I've managed to get it working so thank you for your reply, it's really helped me out. I wanted to add a flashing 'New Highscore' text when a highscore has been beaten but i'm having a little trouble with that.

I've done the following -

System - (Compare Variable) Total Distance>WebStorage.LocalValue("HighScore")
Action - (System) Create Object

The create object is a sprite that says New Highscore, but this doesn't appear when i beat a highscore for some reason, can you tell what i'm doing wrong? I'm also struggling to get the flashing behaviour to work as the sprite doesn't flash even though i've enabled its behaviour and added a Flash action to the Sprite.
B
5
S
2
Posts: 116
Reputation: 867


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest