# Help with Highscore Computation

### » Tue Sep 13, 2011 3:08 am

Since there actually isn't an object that handles a list of highscore I devised a method to do so in my game. Please correct or simplify it if you can do so. Some of it is in code, other bits are just descriptions. I'm not a wiz at coding so if this is wrong please point that out too.

Assumptions:
hsnumb[1...11] = int.
hsname[1...11] = str.
score = int.
name = str.
hsnumb[z] corresponds to hsname[z] (score and name)
there are 10 places in the highscore

Code:
/// for loop
///
for(z=10;z>0;z--;){
if(hsnumb[z]<score){
hsnumb[z+1] = hsnumb[z];
hsname[z+1] = hsname[z];
hsnumb[z] = score;
hsname[z] = name;
}
else
break;
}
/// end of loop
///

Description:
So here's what I did. I initiated a for loop. It starts at 10 and finishes at 1, I hope. If the variable i is not greater than 0 it ends the loop.

If the statement is true then it checks if hsnumb[z] is less than 'score'. If so then hsnumb[z] will be placed 1 below that of itself which would be hsnumb[z+1]. hsname[z] will also be substituted into hsnume[z+1].

Then that same array is substituted by the new score and new name, that is, hsnumb[z] = score, hsname[z] = name.

If the 'If statement' is not true then the whole loop ended since there is no need for it.

Essentially this code systematically goes through the highscore list from 10 to 1 to see if the new score is greater than any one of them. It starts from the bottom since it seemed to be logical and less convoluted from starting from 1. It checks to see if 10th score is less than the new score. If it is true then 10th score is put into a non existing 'garbage' (11th place) which is not displayed nor saved, it is just there as a place holder in prevention of a logical error. After that the 10th place is replaced by the new score (+name).

This code then loops to check the 9th place to see if the new score is greater. If so then substitutions similar to the 10th place mentioned above occurs. 9th score is subbed into 10th score (which was new score) and the new score now subbed into 9th.

The whole process continually repeats until it reaches 1st place or the new score is less than the place it's currently being compared with.

I assume this works in a C++ coded game but I don't know if it's fully possible in the event sheet of CC.

If there's already a tutorial about this without a cap file then I shall initiate a face palm procedure. If you did not understand the code then learn Arrays and For loop.

Please tell me if this is right because I don't want to think about this for any longer. I'm moving onto my highscore save methods.jangsy52011-09-13 03:10:08
B
3
G
1
Posts: 44
Reputation: 563

### » Tue Sep 13, 2011 12:47 pm

CC should handle a bubble sort like this just fine. It should also handle a large (100+) number of entries without slowdown. Maybe use 2 seperate array objects if you'd like to keep hsnumb and hsname seperate.

If you'd like I'll make a cap of this for you.
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

### » Tue Sep 13, 2011 1:30 pm

As Jayjay said, CC will handle this just fine. If you will have larger arrays or are just curious to see other implementations of sort algorithms, you may also want to have a look at Verve!, that presents a divide & conquer algorithm, which always needs the same amount of time to find the right position, no matter if that position will be, for example, the first item in the list or the 10000th. But for a simple 10 place hiscore you won't need it.
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

### » Tue Sep 13, 2011 9:52 pm

Already implemented. Thanks for the feed back too.
B
3
G
1
Posts: 44
Reputation: 563

### » Tue Oct 18, 2011 7:42 am

Hi jangsy5

Could you by any chance tell more about
how you did you highscore, or do you have an
sample file C2

REGARDS
flemmig
B
23
S
12
G
10
Posts: 323
Reputation: 7,382

### » Tue Oct 18, 2011 12:36 pm

flemmig, Construct Classic files are not compatible with Construct 2- they are running off of entirely different code and software. Just about anything made with CC would not be totally applicable to things done in C2.

[QUOTE=Jayjay] CC should handle a bubble sort like this just fine. It should also handle a large (100+) number of entries without slowdown. Maybe use 2 seperate array objects if you'd like to keep hsnumb and hsname seperate.

If you'd like I'll make a cap of this for you.[/QUOTE]

If you were to make one i sure wouldn't try to stop you.
I'd love to see it, hah!

For anyone else reading I would recommend looking at Verve, though the way Verve handles arrays is not exactly something for a beginner to jump right in (you'd have to be familiar a bit with how arrays work before trying to use tulamide's example, though he does explain everything with nice long comments). Then again, the proof is in the pudding- Verve works and works darn well.

All the same I always love to see multiple solutions to common problems and am definitely curious ie this sh*t has stumped me for a good while now.EmperorIng3602011-10-20 01:50:54
B
19
S
3
G
2
Posts: 148
Reputation: 1,945