| Save High Score!!! (simple and has full explanation) 
 
	 
	
		| Author | Message |   
		| xHoly-Divinity 
 
 
 
 
 | 
			
				|  Posted: Thu Jan 20, 2005 8:36 pm    Post subject: Save High Score!!! (simple and has full explanation) |  |   
				| 
 |  
				| I've done some experimenting, and have finally figured out an efficient, non confusing way to save high score (or any other info). You must create a text document in the folder of where your program is located called Highscore.txt. When you create it, type in any number value just so that it has a value (you should type in 0 because technically the high score at this time is 0), then save the .txt file. Here's the code! 
 
 
 	  | Turing: |  	  | 
var check : array 1 .. 1 of int
 %Assigns pathName to 'Highscore.txt'
 const pathName : string := "Highscore.txt"
 var f : int
 %Opens the file to check the old high score
 open : f, pathName, get
 get : f, check (1)
 %Closes the text file
 close : f
 %Checks to see if the new score is higher than the old score
 if score > check (1) then
 %If it is, it will open the file and save the new high score
 open : f, pathName, put
 put : f, score
 close : f
 end if
 %This procedure (same as above) opens 'Highscore.txt'
 var one : int
 var sss : array 1 .. 1 of int
 open : one, "Highscore.txt", get
 get : one, sss (1)
 put "                              HIGH SCORE: ", sss (1)
 
 | 
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Sponsor Sponsor
 
  
   |  |   
		|  |   
		| Tony 
 
  
 
 
 | 
			
				|  Posted: Thu Jan 20, 2005 9:20 pm    Post subject: (No subject) |  |   
				| 
 |  
				| alright, that's good.. a bit confused about why you're using static arrays of size 1 though   
 +20Bits for trying though. Try to modify the code a bit to make the file keep track of top 10 highscores and names... shouldn't be that hard
  |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| xHoly-Divinity 
 
 
 
 
 | 
			
				|  Posted: Wed Feb 23, 2005 6:28 pm    Post subject: (No subject) |  |   
				| 
 |  
				| Quote: 
Try to modify the code a bit to make the file keep track of top 10 highscores and names... shouldn't be that hard
 
 
 Hey tony, I'm running into a few problems with this. In order to save top 10 i would have to compare every single saved score with the score that was earned. Then I would have to place it in the appropriate placing requiring another couple of if statements. Any simpler way of doing this!?
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| jamonathin 
 
  
 
 
 | 
			
				|  Posted: Wed Feb 23, 2005 8:50 pm    Post subject: (No subject) |  |   
				| 
 |  
				| I first got the idea from a previous post that briefly explained a open, put and get, so I just put everything together and got this . . 
 You first need to start with a default base:
 
 	  | code: |  	  | 
%Just so we have a base to work with
 var streamout : int
 var names : array 1 .. 10 of string
 var score : array 1 .. 10 of int % Juss so you don't have to use strint
 open : streamout, "top10", put
 for i : 1 .. 10
 names (i) := "New001"
 put : streamout, names (i)
 score (i) := 1
 put : streamout, score (i)
 end for
 close : streamout
 
 | 
 
 Now here's the actual "top10" part, it calculates the position of the newscore and what not.
 
 	  | code: |  	  | 
%Now we can edit the base record
 var names : array 1 .. 10 of string
 var score : array 1 .. 10 of int
 var newname : string := "Dudeman" %Whatever the name is
 var newscore : int := 48 % whatever the score is
 var streamin, streamout : int
 open : streamin, "top10", get
 for i : 1 .. 10
 get : streamin, names (i)
 get : streamin, score (i)
 locate (i, 1)
 put names (i), " - ", score (i) %Displaying original Top10
 end for
 close : streamin
 for decreasing i : 10 .. 2
 if newscore > score (i) and newscore <= score (i - 1) then
 for decreasing q : 10 .. i
 score (q) := score (q - 1)
 names (q) := names (q - 1)
 end for
 score (i) := newscore
 names (i) := newname
 elsif newscore > score (1) and i = 2 then
 for decreasing q : 10 .. 2
 score (q) := score (q - 1)
 names (q) := names (q - 1)
 end for
 score (1) := newscore
 names (1) := newname
 end if
 end for
 open : streamout, "top10", put
 for i : 1 .. 10
 put : streamout, names (i)
 put : streamout, score (i)
 locate (i, 1) %Displaying new Top10
 put i, ". ", names (i)
 locate (i, 15)
 put " - ", score (i)
 end for
 close : streamout
 
 | 
 
 Well I hope i copy and pasted everything correctly, and i hope it works for yas
  . |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| HyperFlexed 
 
  
 
 
 | 
			
				|  Posted: Wed Feb 23, 2005 10:06 pm    Post subject: (No subject) |  |   
				| 
 |  
				| xHoly-Divinity wrote: Quote: 
Try to modify the code a bit to make the file keep track of top 10 highscores and names... shouldn't be that hard
 
 
Hey tony, I'm running into a few problems with this. In order to save top 10 i would have to compare every single saved score with the score that was earned. Then I would have to place it in the appropriate placing requiring another couple of if statements. Any simpler way of doing this!?
 look up the bubble sort. If that fails, I will be posting the source to my final project soon and an example is in there.
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| xHoly-Divinity 
 
 
 
 
 | 
			
				|  Posted: Thu Feb 24, 2005 4:08 pm    Post subject: (No subject) |  |   
				| 
 |  
				| Thanks man  |  
				|  |  |   
		|  |  |  
	  
		|  |   
		|  |  
 |