Monday, 2 June 2014

How save highscores in local database in Construct 2 game

You have made a game on construct 2 and you want to save the high scores of the player in the local database. Here is a way you can save the high scores of the player in the local database. First of all you will have to add two object into your layout, one for the scores and other for the high scores. The following image is showing the objects of scores and high scores on the layout. 


Now on the event sheet, you need to add two global variables score=0 and highscore=0. Now on the layout you need to add local database object as shown in the image below


Now on the event (Start of layout), you need to make a sub event where select an object webstorage, local key and write HighScore(same as the global variable as it is case sensitive) in the double quotes and click done. In that event set high score to the local web storage. Click on system action, set value, variable should be "HighScore"(same as the global variable as it is case sensitive) and value should be WebStorage.LocalValue("HighScore"), click done. After that set text of the hightscore object to the highscore(this is global variable). Check make another else event and set highscore to 0 and set text of the hightscore object to the highscore(this is global variable). All the steps are shown in the below image.


Now to change the high score when the player dies, what you need to do is to check whether the new scores are greater than the previously high scores that are already stored in the database. When the player collide the with the enemy or player is dead you need to add another sub event which checks whether the new scores are greater than the previous high scores or not. If new new high scores are greater, update the local database with the new score as shown in the image below (which is the example of one of my game).



Now when you play the game at start, the high score will be zero, after that if new scores are greater than the previous scores, new scores will be stored in the local database. You are done :)

3 comments:

  1. hi i have three layouts, Start, Game and End Game, Game layout has the score meter which works perfectly, i want that score to appear on End Game layout and also have high score . i tried this its not working. can you help?

    Regards

    ReplyDelete
  2. If you want your ex-girlfriend or ex-boyfriend to come crawling back to you on their knees (no matter why you broke up) you must watch this video
    right away...

    (VIDEO) Get your ex CRAWLING back to you...?

    ReplyDelete