Jump to content


Photo

adding a high score to custom scores list


  • Please log in to reply
9 replies to this topic

#1 spicydeath82

spicydeath82

    Awesomesauce

  • New Member
  • 138 posts
  • Version:GM8

Posted 23 June 2011 - 02:33 PM

hi. i'm currently working on a project that requires there be multiple custom high score lists.
the problem face is that i'm un sure of how to add a new entry to the list.

here's my score init script:

// initialize the variables
globalvar demo_highscore,demo_highscore_name,demo_score;
demo_score=0;

here's a script i use to check if there's any highscores present and if not then add the default values:

if(demo_highscore[0]>0){exit;} // already has highscores so exit
// no high scores yet so let's set them to default values
else
{
// first place
demo_highscore[0]=1000;
demo_highscore_name[0]="Robert";
// second
demo_highscore[1]=900;
demo_highscore_name[1]="Richard";
//third
demo_highscore[2]=800;
demo_highscore_name[2]="Mark";
// fourth
demo_highscore[3]=700;
demo_highscore_name[3]="Sandy";
//fifth
demo_highscore[4]=600;
demo_highscore_name[4]="Mike";
// sixth
demo_highscore[5]=500;
demo_highscore_name[5]="TV";
// seventh
demo_highscore[6]=400;
demo_highscore_name[6]="Lucian";
// eighth
demo_highscore[7]=300;
demo_highscore_name[7]="George";
// ninth
demo_highscore[8]=200;
demo_highscore_name[8]="Joe";
//tenth
demo_highscore[9]=100;
demo_highscore_name[9]="Casual Gamer";
}
what i need help with is a way to advance the positions down. so given the scores above, say i score 1001 points and get the top score, how do i compare my score to all those in the list, replace the score i've beaten, then shift the old top score from position[0] to [1] and so on down the line?
  • 0

#2 Big J

Big J

    GMC Member

  • GMC Member
  • 2818 posts
  • Version:GM8.1

Posted 23 June 2011 - 03:39 PM

I wrote a script to add a score with a name, shifting stuff down as necessary, but it is untested.

highscoreAdd(score, name)
var i, j, theScore, theName;
theScore = argument0;
theName = argument1;
for (i = 0; i < 10; i += 1)
{
    if (theScore > demo_highscore[i])
    {
        exit_i = true;
        //shift everything down
        for (j = 9; j >= i; j -= 1)
        {
            demo_highscore[j] = demo_highscore[j-1];
            demo_highscore_name[j] = demo_highscore_name[j-1];
        }
        demo_highscore[i] = theScore;
        demo_highscore_name[i] = theName;
        break;
    }
}

Edited by Big J, 23 June 2011 - 03:42 PM.

  • 1

#3 drt_t1gg3r

drt_t1gg3r

    GMC Member

  • GMC Member
  • 3230 posts
  • Version:Unknown

Posted 23 June 2011 - 03:44 PM

bubble sorting and insertion sorting would help here a great deal
  • 0

#4 Big J

Big J

    GMC Member

  • GMC Member
  • 2818 posts
  • Version:GM8.1

Posted 23 June 2011 - 03:48 PM

I was working based on the fact that the array is already sorted, and that all we are doing is adding a new score, and deciding its position in the array, and then shifting everything under the new score downward.
  • 0

#5 drt_t1gg3r

drt_t1gg3r

    GMC Member

  • GMC Member
  • 3230 posts
  • Version:Unknown

Posted 23 June 2011 - 04:11 PM

well that is what bubble sorting and insertion sorting does. it sorts a list of elements depending on it's value. The bubble sorting is the easiest to implement but is costly on large arrays while the insertion sort is a little harder to implement but not so demanding on the processor on larger arrays.

pretty much the bubble sort goes through the array one element at a time
takes the current element and the next element. if the next element is larger then it switches the two elements
it continues doing this until all the elements have been gone through

the video I linked earlier gives a much better detail on how to use it
  • 0

#6 spicydeath82

spicydeath82

    Awesomesauce

  • New Member
  • 138 posts
  • Version:GM8

Posted 23 June 2011 - 11:57 PM

thanks drt_t1gg3r, i'll watch those videos to get my learning on. i've been wanting to learn how to do this for awhile.
Thanks also to Big j. i'll try that code you posted and see if it works the way i want it..
i'll post here again and let you know how it goes.
  • 0

#7 spicydeath82

spicydeath82

    Awesomesauce

  • New Member
  • 138 posts
  • Version:GM8

Posted 24 June 2011 - 12:47 AM

well i tried the code but it threw up an error about a negative array index.

Edited by spicydeath82, 24 June 2011 - 01:06 AM.

  • 0

#8 Big J

Big J

    GMC Member

  • GMC Member
  • 2818 posts
  • Version:GM8.1

Posted 24 June 2011 - 12:49 AM

I should have seen that coming... I used [j-1] as an array index with a full possibility that j could be zero. I'll fix that. See, I had not tested my code. ;)
var i, j, theScore, theName;
theScore = argument0;
theName = argument1;
for (i = 0; i < 10; i += 1)
{
    if (theScore > demo_highscore[i])
    {
        exit_i = true;
        //shift everything down
        for (j = 9; j >= i; j -= 1)
        {
            if (j >= 1) //j cannot be less than 1
            {
                demo_highscore[j] = demo_highscore[j-1];
                demo_highscore_name[j] = demo_highscore_name[j-1];
            }
        }
        demo_highscore[i] = theScore;
        demo_highscore_name[i] = theName;
        break;
    }
}

Edited by Big J, 24 June 2011 - 12:53 AM.

  • 1

#9 spicydeath82

spicydeath82

    Awesomesauce

  • New Member
  • 138 posts
  • Version:GM8

Posted 24 June 2011 - 03:01 AM

lol. k. i'll try that change and see what happens.
  • 0

#10 spicydeath82

spicydeath82

    Awesomesauce

  • New Member
  • 138 posts
  • Version:GM8

Posted 24 June 2011 - 03:40 AM

Works. thanks man. made a high scores room just to see how it worked. does great. thanks a million.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users