How do I save highscore on the device in a auto runner game?

Get help using Construct 2

Post » Thu Mar 09, 2017 2:22 pm

I have been working with the "Template-AutoRunner", that comes with c2. I want to store the score locally to the device. I saw many tutorials about using the local storage , but non-of these worked with auto runner :roll: :?: :cry:
B
12
S
4
Posts: 32
Reputation: 1,033

Post » Thu Mar 09, 2017 3:15 pm

If you are running it in a browser you can use save and load in the systems commands and that will save your score and where you stopped playing and that data can be used when you load the game for other purposes.

If you are using an NW.js game then someone else will have to help you with local storage as that is not something I have played around with much?
Banned User
B
27
S
7
G
58
Posts: 1,229
Reputation: 34,780

Post » Thu Mar 09, 2017 3:27 pm

rafay123 wrote:I have been working with the "Template-AutoRunner", that comes with c2. I want to store the score locally to the device. I saw many tutorials about using the local storage , but non-of these worked with auto runner :roll: :?: :cry:


I'm working on an auto-runner and save the High Score locally using local storage.

Add the LocalStorage object

Add global variables Score=0 and HighScore=0

Initialise your high score:
System: On start of layout
-> LocalStorage: Get item "HighScore"

LocalStorage: On item "HighScore" get
-> System: Set HighScore to int(LocalStorage.ItemValue)

In your level end event (where you'd show the high score and have a restart button), add a sub-event:
System: Compare Score > HighScore
-> System: Set HighScore = Score
-> LocalStorage: Set item "HighScore" to HighScore
Vote for all the Construct 2 games on Steam Greenlight - Find them here
B
33
S
9
G
7
Posts: 450
Reputation: 6,778

Post » Thu Mar 09, 2017 3:33 pm

OddConfection wrote:
rafay123 wrote:I have been working with the "Template-AutoRunner", that comes with c2. I want to store the score locally to the device. I saw many tutorials about using the local storage , but non-of these worked with auto runner :roll: :?: :cry:


I'm working on an auto-runner and save the High Score locally using local storage.

Add the LocalStorage object

Add global variables Score=0 and HighScore=0

Initialise your high score:
System: On start of layout
-> LocalStorage: Get item "HighScore"

LocalStorage: On item "HighScore" get
-> System: Set HighScore to int(LocalStorage.ItemValue)

In your level end event (where you'd show the high score and have a restart button), add a sub-event:
System: Compare Score > HighScore
-> System: Set HighScore = Score
-> LocalStorage: Set item "HighScore" to HighScore


I have a question on that:

If the get returns nothing will it just put zero in the high score or do you need to check first if "highscore" has a value in it?
Banned User
B
27
S
7
G
58
Posts: 1,229
Reputation: 34,780

Post » Thu Mar 09, 2017 4:03 pm

lamar wrote:If the get returns nothing will it just put zero in the high score or do you need to check first if "highscore" has a value in it?


I believe it will return 0 if there is nothing there, same as if you use the ItemValue outside of the On Get event.

At least, that's how it seems to work in my game.
Vote for all the Construct 2 games on Steam Greenlight - Find them here
B
33
S
9
G
7
Posts: 450
Reputation: 6,778

Post » Thu Mar 09, 2017 4:06 pm

OddConfection wrote:
lamar wrote:If the get returns nothing will it just put zero in the high score or do you need to check first if "highscore" has a value in it?


I believe it will return 0 if there is nothing there, same as if you use the ItemValue outside of the On Get event.

At least, that's how it seems to work in my game.


Ok thanks I will give it a try.

I think that is what kept it from working for me as I was checking the value and nothing there to check.
Banned User
B
27
S
7
G
58
Posts: 1,229
Reputation: 34,780


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 24 guests