Ok, i'm stumped again, I though maybe it was something with my program, so i wrote a seperate program to debug a high score system...
Can someone tell me what i'm doing wrong?:
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")
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
heres what I get:
Making 3 Highscores, bri 12, str 15, and evr 13...
Reading High score file...
High Score: evr 13 Points
Deleting bri's highscore...
Reading High score file...
High Score: evr 13 Points
Clearing File...
Its apparent that the problem either sits within the ReadHS() function or the AddHS() function.. But both look correct.
Whats suppost to happen is:
1. It makes 3 Highscores, bri 12, str 15, and evr 13...
2. It reads the high scores and prints the result - DOES NOT WORK CORRECTLY
3. It deletes bri's HS by loading into memory editing, and writing the file back out.
4. It reads the high scores again, this time it should be missing bri's - THIS DOES NOT WORK
Its only printing evr's HS.
Anyone know whats wrong?
PS. To run the program you need to save the source then make a notepad file named "hs.data" in the same directory, empty of course.