Problems with creating a high-score.

Get help using Construct 2

Post » Tue Feb 18, 2014 3:27 pm

Hey everyone,

I've been working with construct for the past couple of days and suffice to say that I am thrilled with the progress I've made. My project started as this small "man i'm bored" thingy and evolved into a potential playstore/appstore game! WOW.

However, I still face some problems that I can't seem to solve. The biggest issue I have at this point is setting up the high score. I have followed http://www.youtube.com/watch?v=06-LgQxceGg and did everything the tutor said, but no luck. Instead of a high-score I am getting a 0 every time.

I guess the problem lies in one of the global variables I have and the way the game controls them. For instance, the score in my game is determined in seconds. The longer the player survives the bigger the score he gets. This is determined by a global variable which is TotalTime. At the moment the player dies, another global variable, called EndTime kick in. This global variable adds TotalTime to 0, thus detecting the moment the player died. Of course, it is followed by set text EndTime.

So, as you may see, my scoring system works, every time a player dies, he gets a small you failed - score 10,3 screen. The problem is, I can't seem to get the game to recognize the biggest value and create a high score to pursue. Any ideas?

Thank you for all the ideas and help you guys offer, this is probably the most helpful forum I have ever seen :)
B
9
S
1
Posts: 51
Reputation: 644

Post » Tue Feb 18, 2014 3:42 pm

Not 100% sure I understand exactly what you want to do. But if I got it correct, the player have to survive for as long as possible, and the time that he survived will be the score, next game, this score should be the high score if it was higher than the former high score and so on?

If that's the case, you need to make sure that each time you start a new game, you don't do a reset layout that reset the high score to 0. This can happen if the global variable are in the same event sheet as the game, so when you reset it, it will be whatever it was when the layout was started the first time.

A simple way to solve this, would be to just make a object where you store the high score, and the current score that the player just made. And make the object global.

Then after each game, you just check these values against each other, and write the high score from this object.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Tue Feb 18, 2014 3:46 pm

Thanks for such a swift response.

What type of object should this be. Any examples on how to do this? Possibly a capx?
B
9
S
1
Posts: 51
Reputation: 644

Post » Tue Feb 18, 2014 3:59 pm

It should just be a sprite, that you place outside the screen on another layout.

Alternative, you can also just add another event sheet and include it in the current one, and just add the high score and current score as global variables there.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Tue Feb 18, 2014 5:04 pm

Resetting the layout is fine as long as you first store your current score in a global variable. Then at the end of the level BEFORE calling restart layout, etc... compare the CurrentScore variable to the HighScore Variable and if it is greater, store CurrentScore in HighScore. Then reset the layout.
B
49
S
12
G
10
Posts: 1,833
Reputation: 14,603

Post » Tue Feb 18, 2014 5:26 pm

Run the game in debug mode and watch your global variables.
B
11
S
2
Posts: 68
Reputation: 982

Post » Tue Feb 18, 2014 11:37 pm

Hey Everyone, sorry for the late reply.

I think that the problem lies somewhere in the WebStorage object. I am going to literally write down what I have put into the event sheet.

Local Key "HighScore" exists - set HighScore to int(WebStorage.LocalValue(HighScore))
else
System - Set HighScore to 0

moving further down the event sheet.
If player collides with the enemy

player - destroy
Txt(score) - destroy
set EndTime to 0 + Total Time
Wait 1.5 secs
Create object txt(result)(basically your score for that game)
set txt(result) to EndTime
Wait 0.3 sec
Create txt(Try Again)
Txt(Try Again) set text to "Tap here to try again"

SubEvent to this event.
System - If EndTime > HighScore then WebStorage set local key to "HighScore"
Set text(HS) to HighScore

This is basically it. Every time I play it I get the score of 0. Any ideas?
B
9
S
1
Posts: 51
Reputation: 644


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 3 guests