View Single Post
Old May 9th, 2006, 7:42 AM   #4
Evenfall
Newbie
 
Join Date: May 2006
Posts: 9
Rep Power: 0 Evenfall is on a distinguished road
Changed code

ok i changed the code around a bit its now:

      {HighScores}

AssignFile(ScoresFile, 'Scores.dat');  {assigns the variable 'Scores File' to the file 'Scores.dat' on the HDD}
reset(ScoresFile);      {resets the file pointer to the begining of the file}

while not eof(ScoresFile) do

      begin
            read(ScoresFile, HighScoresData);   {reads all of the data on the file to the highscores record}
      end;    {while}
CloseFile(ScoresFile);
if Score > HighScore[10].Score then   {if player's score is greater than the 10th highscore than the player's score becomes the 10th highscore}

      begin
          begin

          HighScore[10].Score:=Score;
          HighScore[10].Name:=InputBox('HighScores', 'Congradulations you got a high score!', 'Enter your name here');  {player's name is entered into the record}
          HighScoresCont := true;  {condition to start the sorting process is set to true}
          end;



          while HighScoresCont do    {while the highscorescont is true the program will sort the highscores from highest to lowest}
	             begin
               HighScoresCont := false;
               for HSSort:= 1 to 10 do
		                if HighScore[HSSort].Score < HighScore[HSSort+1].Score
		                    then begin
			                      HSTemp := HighScore[HSSort].Score;
                            HighScore[HSSort].Score := HighScore[HSSort+1].Score;
			                      HighScore[HSSort+1].Score := HSTemp;
			                      HighScoresCont := true;
			                  end;                  {if}
               end;                                           {while}


Inputname:=True; {condition to allow option to view highscores}
AssignFile(ScoresFile, 'Scores.dat');
Reset(ScoresFile);   {resets the file pointer to the begining of the file}
write(ScoresFile, HighScoresData);  {the highscores record is written to disk} {this line is highlighted in blue when the error message occurs}
CloseFile(ScoresFile); {closes 'ScoresFile', saving any new information}
end; {if get highscore greater than highscore[10]}


if InputName = True then     {if name has been entered then option to view highscores is given to the player}
    begin
    InputName:=False;
       ViewHS := MessageDLg('Do you want to view highscores?', mtConfirmation, [mbYes, mbNo], 0) = mrYes;
         if ViewHS then
             begin
                 FrmHighScores.show;
                 FrmMainGame.Visible:=False;
             end;
   end;
end;
end;

and now i dont get the error message..

HOWEVER i have new problems..

1. i have to enter my name 10 times, i would like ot only enter it once...
2. the scores do not get displayed on the highscores page.

the code for the highscores page is

procedure TFrmHighScores.FormCreate(Sender: TObject);
begin

if FrmHighScores.Visible=True then
  begin
      AssignFile(ScoresFile, 'Scores.dat');
      Reset(ScoresFile);
          while not eof(ScoresFile)do
              begin
                  read (ScoresFile, HighScoresData);
              end;
      LblName1.Caption:=HighScore[1].Name;
      LblName2.Caption:=HighScore[2].Name;
      LblName3.Caption:=HighScore[3].Name;
      LblName4.Caption:=HighScore[4].Name;
      LblName5.Caption:=HighScore[5].Name;
      LblName6.Caption:=HighScore[6].Name;
      LblName7.Caption:=HighScore[7].Name;
      LblName8.Caption:=HighScore[8].Name;
      LblName9.Caption:=HighScore[9].Name;
      LblName10.Caption:=HighScore[10].Name;

      LblScore1.Caption:=IntToStr(HighScore[1].Score);
      LblScore2.Caption:=IntToStr(HighScore[2].Score);
      LblScore3.Caption:=IntToStr(HighScore[3].Score);
      LblScore4.Caption:=IntToStr(HighScore[4].Score);
      LblScore5.Caption:=IntToStr(HighScore[5].Score);
      LblScore6.Caption:=IntToStr(HighScore[6].Score);
      LblScore7.Caption:=IntToStr(HighScore[7].Score);
      LblScore8.Caption:=IntToStr(HighScore[8].Score);
      LblScore9.Caption:=IntToStr(HighScore[9].Score);
      LblScore10.Caption:=IntToStr(HighScore[10].Score);

      CloseFile(ScoresFile);
  end

end;

the record and file variables are declared exactly the same as htey are for the first section of code (main game code)

if anybody can help it would be greatly apriecated...i dont have much time left to hand this in...
Evenfall is offline   Reply With Quote