read file,load file help

BlitzMax Forums/BlitzMax Beginners Area/read file,load file help

mudcat(Posted 2005) [#1]
I have a global list:tlist=createlist() in my tscore type.
To read a file of highscores,I use this right before my main.
''''''''''''''load highscores'''''''''
If FileType("highscores.dat") = 0 Then 
Local new_file = CreateFile("highscores.dat")
End If
Local Read_file = ReadFile("highscores.dat")

While Not Eof(Read_file)
For Local x:tscore=EachIn tscore.list
x.name=ReadLine(Read_file)
x.score=Readint(read_file)
x.level=Readint(read_file)
Next
Wend

CloseStream(Read_file)

At the end of the game,I save the file this.
'''''''''''''''save highscores'''''''''
Local write_file = WriteFile("highscores.dat")
For Local x:tscore=EachIn tscore.list
WriteLine(write_file,x.name)
WriteInt(write_file,x.score)
WriteInt(write_file,x.level)
Next
CloseStream(write_file)

Did alright the first time it ran,froze after that.Could someone point me in the right direction.

Thanks,
mudcat


mudcat(Posted 2005) [#2]
Guess what,I found the problem.
Instead of this
While Not Eof(Read_file)
For Local x:tscore=EachIn tscore.list
x.name=ReadLine(Read_file)
x.score=Readint(read_file)
x.level=Readint(read_file)
Next
Wend

I replaced it with this.
While Not Eof(Read_file)
 Local x:tscore=New tscore
x.name=ReadLine(Read_file)
x.score=Readint(read_file)
x.level=Readint(read_file)
tscore.list.addlast x
Wend

I realized that the tscore list didn't have anything in it,so I had to create new objects.Sorry if you guys already knew this,maybe this will help someone else?

Thanks,
mudcat


WendellM(Posted 2005) [#3]
Yes, it's always nice to post the answer, even if you figure it out yourself. That way if someone in the distant future has a similar problem and comes across a thread, they'll find the solution. :)