Save file: how?

Blitz3D Forums/Blitz3D Beginners Area/Save file: how?

RogueM(Posted 2007) [#1]
I need to create a function that lets the player save and load a game, how do I do this?


stayne(Posted 2007) [#2]
Take a look at WriteFile and ReadFile in the help area of Blitz3D.


RogueM(Posted 2007) [#3]
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.


stayne(Posted 2007) [#4]
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.


jhocking(Posted 2007) [#5]
Don't use ReadInt, ReadString, etc. use ReadLine.


Matty(Posted 2007) [#6]
Nothing wrong with using readint and readstring, as long as you make sure you wrote them with writeint and writestring


Mortiis(Posted 2007) [#7]
There is a lot of threads in the forum about it. Search...


GfK(Posted 2007) [#8]
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.