New problem, when I want to display these high scores, i want them to be in order...
So, i turned to list sorting (never tried it before, but it beats coming up with your own sorting function)
Anyways, its not working, and my lack of knowlege of it is sucking at the moment.
anyways heres the code... modifications are under the ReadHS() function and a new method under TFileMemory:
here's my debug session, It's behaving similar to before, only printing the last entry, but its printing it 3 times like there is 3 highscores there (which is correct)... then after deleting bri's, it prints it 4 times (whhhaaat...?)
also, this is my reference to how TLists sort, though its kinda old, and might be changed:
http://www.blitzbasic.com/Community/posts.php?topic=50278
Thanks in advance!
So, i turned to list sorting (never tried it before, but it beats coming up with your own sorting function)
Anyways, its not working, and my lack of knowlege of it is sucking at the moment.
anyways heres the code... modifications are under the ReadHS() function and a new method under TFileMemory:
SuperStrict Global FileMemoryList:TList = CreateList() Type TFileMemory Field initals:String, points:Int Method AddToList:TFileMemory() ListAddLast(FileMemoryList,Self) End Method Method RemoveFromList:TFileMemory() FileMemoryList.Remove(Self) End Method '.............................MOD Method Compare:Int(p:Object) Local pr:TFileMemory = TFileMemory(p) If(Self.points < pr.points) Then Return True Else Return False End If End Method '..............................End mod End Type Function AddHS(i:String,p:Int) If Len(i) > 3 Return End If Local file:TStream = OpenFile("hs.data",True,True) SeekStream(file,StreamSize(file)) 'seek to end of file WriteString(file,i) WriteInt(file,p) CloseFile(file) End Function Function ReadHS() Local filestore:TFileMemory Local file:TStream = ReadFile("hs.data") While Not Eof(file) filestore:TFileMemory = New TFileMemory filestore.AddToList() filestore.initals = ReadString(file,3) filestore.points = ReadInt(file) Wend '...........................................MOD FileMemoryList.Sort() For Local i:TFileMemory = EachIn FileMemoryList Print "High Score: "+filestore.initals+" "+filestore.points+" Points" Next '...........................................END MOD CloseFile(file) FileMemoryList.Clear() End Function Function RemoveHS(i:String) Local filestore:TFileMemory Local file:TStream = ReadFile("hs.data") While Not Eof(file) filestore = New TFileMemory filestore.AddToList() filestore.initals = ReadString(file,3) filestore.points = ReadInt(file) If filestore.initals = i filestore.RemoveFromList() End If Wend CloseFile(file) file = WriteFile("hs.data") For Local b:TFileMemory = EachIn FileMemoryList WriteString(file,b.initals) WriteInt(file,b.points) Next CloseFile(file) End Function Function ClearHS() Local file:TStream = WriteFile("hs.data") CloseFile(file) End Function Print "" Print "Making 3 Highscores, bri 12, str 15, and evr 13..." 'un sorted as you can see.... AddHS("bri",4) AddHS("str",77) AddHS("evr",2) Print "" Print "Reading High score file..." 'this function should sort them aswell (by points) ReadHS() Print "" Print "Deleting bri's highscore..." RemoveHS("bri") Print "" Print "Reading High score file..." ReadHS() Print "" Print "Clearing File..." ClearHS() End
here's my debug session, It's behaving similar to before, only printing the last entry, but its printing it 3 times like there is 3 highscores there (which is correct)... then after deleting bri's, it prints it 4 times (whhhaaat...?)
Reading High score file... High Score: evr 2 Points High Score: evr 2 Points High Score: evr 2 Points Deleting bri's highscore... Reading High score file... High Score: evr 2 Points High Score: evr 2 Points High Score: evr 2 Points High Score: evr 2 Points
also, this is my reference to how TLists sort, though its kinda old, and might be changed:
http://www.blitzbasic.com/Community/posts.php?topic=50278
Thanks in advance!