Save file: how?
Blitz3D Forums/Blitz3D Beginners Area/Save file: how?| 
 | ||
| I need to create a function that lets the player save and load a game, how do I do this? | 
| 
 | ||
| Take a look at WriteFile and ReadFile in the help area of Blitz3D. | 
| 
 | ||
| It writes fine, but when I try to load it using readint,readstring,ect., it says"stream does not exist", even after I load the file with "readfile("myfile.dat")" or "readfile("myfile.dat")" i've tried "variable=readfile("myfile.dat")" and "readfile(file1)" file1 is what is called the file handle. | 
| 
 | ||
| Take a look here: http://www.blitzbasic.com/codearcs/codearcs.php?code=1171 It's not very efficient as a whole but the basics you need are there. | 
| 
 | ||
| Don't use ReadInt, ReadString, etc. use ReadLine. | 
| 
 | ||
| Nothing wrong with using readint and readstring, as long as you make sure you wrote them with writeint and writestring | 
| 
 | ||
| There is a lot of threads in the forum about it. Search... | 
| 
 | ||
|  i've tried "variable=readfile("myfile.dat")" and "readfile(file1)" file1 is what is called the file handle.  
;create a file and put something in it
file1 = WriteFile("myfile.dat")
  WriteLine file1,"Hello"
CloseFile file1
;read file back
file1 = ReadFile("myfile.dat")
While Not Eof(file1)
  s$ = ReadLine(file1)
  Print s$
Wend
CloseFile file1
Don't use OpenFile - it will fail on read-only files. |