I'm talking about when you first write the file to the hard drive in the AddHS() function. When you open the file and write the next high score, it erases the first one you wrote.
Although in testing, I discovered that the contents are not immediately erased, so you can seek to the end of the file before writing the next high score which will then append the next line.
Notice the change I made in AddHS().
Your remove function works just fine once that change is made.
Although in testing, I discovered that the contents are not immediately erased, so you can seek to the end of the file before writing the next high score which will then append the next line.
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 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) Print "High Score: "+filestore.initals+" "+filestore.points+" Points" Wend 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..." AddHS("bri",12) AddHS("str",15) AddHS("evr",13) Print "" Print "Reading High score file..." ReadHS() Print "" Print "Deleting bri's highscore..." RemoveHS("bri") Print "" Print "Reading High score file..." ReadHS() Print "" Print "Clearing File..." ClearHS() End
Notice the change I made in AddHS().
Your remove function works just fine once that change is made.