Local high score (SOLVED)

Get help using Construct 2

Post » Wed Feb 19, 2014 3:36 am

the video was very helpful as he has his set similar to mine for the score. Have everything working except the scoring chart at the end it looks like. Can one of you smarter people check my syntax to see if you see anything that stands out here?

Threw up a picture of the start, scoring, and collisions (which end the level and destroy all objects


http://game.reconone.info/files/settings.jpg
B
6
Posts: 17
Reputation: 332

Post » Wed Feb 19, 2014 8:54 am

@sotak, first of all, I would put most of the code in the collision section in a function so you don't have to duplicate the code so many times...

Also, you have several problems with webstorage. You are saving the text "Score" instead of the value of the Score variable, and you don't need to do that every time the score changes. Webstorage is for saving data when you close the game after you are done playing. Then the next time you open the game you can load the data back in (to keep a local all time high score for example). But you are resetting the webstorage "Highscore" field at the start of the game, in event 2, which would wide out the previous high score (if it was being correctly saved). And, on top of that, there are a couple places (events 3 and 7) where you do not have Highscore in quotes - so Construct2 will use the value of the Highscore global variable of zero, rather than the text key "Highscore".

Now, for the main problem you asked about at the end of the game, it looks like you are setting the Highscore text object to be visible, but I don't see any place where you give it a value.

So, the main thing to keep straight in your head is that you have three completely separate things here: 1) the global variable Highscore that keeps track of the highest score achieved by the play while the game is running. 2) the Highscore text object that can be used to show that high score to the player on the screen. And 3) the Webstorage "Highscore" field that can permanently save the high score on the players computer hard drive when they quit the game.

The main flow should go something like this: Load in Highscore from Webstorage if it exists, otherwise create it and set it to zero. Set score to zero. Play game. You have the right idea in event 7, where you add 1 to Score. (but you can take out the Webstorage line there)
Then when the game ends you want to check if Score > Highscore, then set Highscore = Score, and save it to webstorage. Then set the text object Highscore to something like "Your score="&Score&", High Score="&Highscore... then button to restart the game...AllanR2014-02-19 09:11:30
B
95
S
33
G
20
Posts: 438
Reputation: 17,640

Post » Thu Feb 20, 2014 5:09 am

AllanR wrote:@sotak, first of all, I would put most of the code in the collision section in a function so you don't have to duplicate the code so many times...


Yeah working on that part haha, its very cluttered right now

You are saving the text "Score" instead of the value of the Score variable, and you don't need to do that every time the score changes.
But you are resetting the webstorage "Highscore" field at the start of the game, in event 2

I changed it around a bit more (tried to make it the same score style as the video)

Do you mean setting the Score to 0 is resetting the Highscore field? or the global number part






took a screenshot of the video that was linked to show the settings compared to me.
I even made my names for the txt boxes/keys the same

Seems like its just one little part that is off but everything looks the same as far as add 1 score (100 for his) and the storage keys.
http://game.reconone.info/files/new.jpg



I tried to follow the steps AllanR mentioned along with copying the wording that he used in the video as our structure is for the score is practically the same.
B
6
Posts: 17
Reputation: 332

Post » Thu Feb 20, 2014 6:33 pm

I got it to work!

Not sure how...But was reading some other posts on webstorage just adding in code and changing it around and now it works. Ill upload a fresh copy after i clean it up so anyone looking at this can see what I did (and point out a better way if possible)
Might be next week sometime, as Im going hunting tomorrow-sunday...but its now saving the highscore!!!!


Thanks for everyones help, now just gotta figure out what exactly i did that made it work haha so i can use it later in future games

The last changes I made were following the idea Aphrodite gave herehttps://www.scirra.com/forum/viewtopic.php?f=147&t=95354&hilit=highscore


I "Think" it was that the game over section (after collision) it was not pulling the saved highscore? maybe...idk Ill try to figure that out and post a full SS / the actual file to help anyone else out who is trying this kind of idea
B
6
Posts: 17
Reputation: 332

Post » Fri Feb 28, 2014 11:53 pm

Any chance of that capx?
B
47
S
15
G
3
Posts: 201
Reputation: 4,625

Post » Tue Mar 04, 2014 9:04 pm

Nitro187 wrote:Any chance of that capx?



Yeah been busy lately, ill upload what i have though it is messy so hah

Ive added some more comments to hopefully help anyone else trying this kind of local score setup

https://dl.dropboxusercontent.com/u/146 ... flyer.capx
B
6
Posts: 17
Reputation: 332

Previous

Return to How do I....?

Who is online

Users browsing this forum: evillair and 9 guests