Help with Highscore Computation

This forum is currently in read-only mode.
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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.

  • Already implemented. Thanks for the feed back too.

  • 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

  • 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.

    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.

    If you were to make one i sure wouldn't try to stop you. <img src="smileys/smiley2.gif" border="0" align="middle" />

    <font size="2">I'd love to see it, hah!</font>

    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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)