: Hi guys,
: I need some help in code,
: If u are say, making a game, right, and someone gets a high score (saved as ‘score’); and it is in 2nd place out of 3, how can you shift down the other scores. I am using arrays of records to store name and score
: (like ‘person[count].name;
: person[count].scr (for score);’
:
: im saving the files in high.txt
:
: what im doing is reading the values from file, when ‘score>person[count].scr then begin’
: and I don’t know how to make the scores below that one shift down and in turn, the score 3 will be deleted.
:
: So if the score is 1st then ‘
: person[1].name:= person[2].name;
: and person[1].scr := and person[2].scr;
: e.t.c e.t.c …..
:
: is there an easier way that incorporates counts and so on…
: thanx!
you are on the right track. But instead of typing them out each time, use a loop such as:
{ If they get 2nd place then Start = 2 }
{ The first # will always be 1 less than the # of high score }
{ positions because the last place doesn't get saved. }
For X := 2 downto Start Do
Begin
person[Start+1].Name := person[Start].Name;
person[Start+1].Scr := person[Start].Scr;
...
End;
Now even this is not the greatest. We can make this even shorter like this:
For X := 2 downto Start Do
person[Start+1] := person[Start]; { Copy the whole record }
Easy as pie.... Mmmm... Pie....
Yeah... well, hope this helps.
Phat Nat