High score on local?

Get help using Construct 2

Post » Wed Feb 29, 2012 12:59 pm

Hi,

I want to create a Highscore of top 10 on local. When I search the entire forum all I found is an online high score tutorial/plugin. Is there a way to make this table an put it in a webstorage to access it locally?

Thanks in advance
B
17
S
3
G
3
Posts: 109
Reputation: 2,747

Post » Wed Feb 29, 2012 1:12 pm

Sure, just save the top 10 in a "list" (take a look at the Token At section), seperated by a delimiter and store this string thru WebStorageWeishaupt2012-02-29 13:17:05
B
42
S
19
G
12
Posts: 723
Reputation: 13,911

Post » Wed Feb 29, 2012 1:53 pm

i'm not really a programmer.
i dont really understand how token at works. can u explain it a bit?
B
17
S
3
G
3
Posts: 109
Reputation: 2,747

Post » Wed Feb 29, 2012 2:01 pm

Did you take a look at the two tutorials I linked?

The Random Animation Tut explains the "list" with TokenAt.....
B
42
S
19
G
12
Posts: 723
Reputation: 13,911

Post » Sat Sep 08, 2012 6:03 pm

Hi there!
I'm trying to get a local highscore working as well, and I looked at the 2 tutorials.

This is my capx:
slurp.capx

and this is the event code excerpt:


The "WebStorage: Set local key..." doesn't seem to work (or I'm using it in the wrong way).
The variable "highscores" is my global variable that contains all the highscores, concatenated so that I can draw single pieces out using "tokenat".
"savedHighscores" is supposed to be the key for the cookie storage.

As you can see, I have a "debugText" textbox where I print some things for debugging. When I debug-print my own global value "highscores", the correct concatenation is being displayed (this line is set to "toggle disabled" in the screenshot).
But when I put the key "savedHighscores" into the debug text, then nothing shows, it's empty.

What am I doing wrong?Aeris852012-09-08 18:05:29
B
4
Posts: 12
Reputation: 374

Post » Sat Sep 08, 2012 6:33 pm

@Aeris85: You're trying to display a key named "savedHighscores" when you actually have saved in a key named "savedHighscore" (without the ending "s").

It's simply not the same key.Kyatric2012-09-08 18:34:24
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,805

Post » Sat Sep 08, 2012 6:42 pm

Darn, typo, I just realized it as well xD !

Okay, so here my next problem:

For displaying my highscores, I use the following formatting (global variable version):
[code]"1. " & tokenat(highscores, 0, ":") & "     " & tokenat(highscores, 1, ":")[/code]
This works!!
The "tokenat" function extracts the correct parts of my loooooong "highscores" string.

So now, when I want to replace that with the "webStorage" saved string, I had to do this, right (WebStorage version)?
[code]"1. " & tokenat(WebStorage.LocalValue("savedHighscore"), 0, ":") & "     " & tokenat(WebStorage.LocalValue("savedHighscore"), 1, ":")[/code]
Namely replacing the "highscores" with "WebStorage.LocalValue("savedHighscore")".
But this does not work. When I enter one highscore, close the game and reopen it, the old highscore isn't there anymore.
B
4
Posts: 12
Reputation: 374

Post » Sat Sep 08, 2012 7:53 pm

@Aeris85: You should start a new topic rather than hi-jacking old ones and provide updated capx (uploaded on dropbox preferably) with/for each new question.

The problem here is that you set the key to a new value before displaying it.
You're missing some point in your project that first loads the values from the webstorage into the global variable "highscores".

It's just a matter of logic of the actions here.

I talk more about this in the "Webstorage" section of my tutorial "Asteroid in less than 100 events".Kyatric2012-09-08 19:54:36
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,805

Post » Sat Sep 08, 2012 10:44 pm

Hmm, imho it's better to use an existing topic that is _just about_ my questions (=tokenat and WebStorage for a highscore list) rather than creating a new one, asking the same thing and appending some little stuff.

Thank you for your advice, I think I'll get it done from this point on!
I just looked into your tutorial: seams like a hell lot of work, and I'll read it to learn more stuff.
B
4
Posts: 12
Reputation: 374


Return to How do I....?

Who is online

Users browsing this forum: newt and 18 guests