Files - Reading, Writing, Opening, Closing

Community Forums/Showcase/Files - Reading, Writing, Opening, Closing

wizzlefish(Posted 2004) [#1]
OK - so this may not be an achievement for most of you, but I just found out how to write data to a *.dat file in Blitz!!


OK, I admit to getting it out of the Command Reference in Blitz3D, but I just thought it was awesome. I have a few questions, though:

1) How would I store three different sets of name, score, and level, and read them? Would I have to create a different DAT file for each?

2) What happens if you don't do "CloseFile?" I tried doing it, and nothing noticable happened.

3) Is there a way to store more than one String, Int, and Byte? Such as this:
score = WriteInt(file)
x = WriteByte(file)
y = WriteByte(file)
z = WriteByte(file)
currentgun = WriteString$(file)
name = WriteString$(file)


4) What is the difference between a byte and an int?


gosse(Posted 2004) [#2]
1) Just do a loop and store them all.
2) The file will only be closed at the end of execution.
3) Yes, you can store as many of each of them that you want.
4) Byte takes only 1 byte and an Int takes 4 bytes.


wizzlefish(Posted 2004) [#3]
How do I read an individual String.
I save two strings:
name = WriteString(file)
name2 = WriteString(file)

How would I read two strings?
nameread = ReadString(file)
nameread2 = ReadString(file)

How does the computer know which string to read?


Beaker(Posted 2004) [#4]
WriteString(file),name
WriteString(file),name2

nameread = ReadString(file)
nameread2 = ReadString(file)

They are read in the order you wrote them.


wizzlefish(Posted 2004) [#5]
Thanks!