adding a high score to custom scores list
#1
Posted 23 June 2011 - 02:33 PM
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?
#2
Posted 23 June 2011 - 03:39 PM
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.
#4
Posted 23 June 2011 - 03:48 PM
#5
Posted 23 June 2011 - 04:11 PM
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
#6
Posted 23 June 2011 - 11:57 PM
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.
#7
Posted 24 June 2011 - 12:47 AM
Edited by spicydeath82, 24 June 2011 - 01:06 AM.
#8
Posted 24 June 2011 - 12:49 AM
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.
#9
Posted 24 June 2011 - 03:01 AM
#10
Posted 24 June 2011 - 03:40 AM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











