Files - Reading, Writing, Opening, Closing

Miscellaneous Forums/Blitz Showcase/Files - Reading, Writing, Opening, Closing

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

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!!
;Type to store info
Type highscore
  Field name$
  Field score%
  Field level%
End Type

best.highscore = New highscore
best\name = Input("Name - ")
best\score = Input("Score - ")
best\level = Input("Level - ")

;open or create a file to write to
scorefileout = WriteFile("score.dat")

;Write info
WriteString(scorefileout, best\name)
WriteInt(scorefileout, best\score)
WriteByte(scorefileout, best\level)

;close the file
CloseFile(scorefileout)

;open the file to read the data
scorefilein = ReadFile("score.dat")

;read info previously stored
read.highscore = New highscore
read\name$ = ReadString$(scorefilein)
read\score = ReadInt(scorefilein)
read\level = ReadByte(scorefilein)

;close the file once reading is done
Print "High Scores:"
Print ""
Write "Name - "
Print read\name
Write "Score - "
Print read\score
Write "Level - "
Print "read\level

WaitKey()
End


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?