Game Design Music and Art

Blitz basic file read problem – !▀rendan

!▀rendan

Member

Posts: 21
From: Western Australia
Registered: 07-04-2002
*.bb
-------------------------
SeedRnd(MilliSecs())
number=Rnd(2)
file=ReadFile("data.txt")
SeekFile (file, number)
Print ReadLine$( file )

Print number
MouseWait
End
-------------------------
data.txt
-------------------------
line1
line2
line3
-------------------------

I've made some progress, so far this is my blitz basic code, and my data file.

The problem I have is in this section of code.

SeekFile (file, number)

I want the random number to represent a line (e.g. 0=line1,1=line2,2=line3)
But the SeekFile command uses the random number to move to a corresponding byte, not a different line.

eg.

012
line1

0=line1
1=ine1
2=ne1

If you copy the code and create the data file you can get a better view of what I'm trying to say... I you can help it would be awesome!

------------------
-{!▀rendan}-

Ty

Member

Posts: 45
From: England
Registered: 05-15-2002
Hi, nice to see you around !▀rendan

Personally, I wouldn't use the seekfile command, so here's how I'd do it :


SeedRnd(MilliSecs())
number=Rand(1,3)

file=ReadFile("data.txt")

For i=1 To number-1
ReadLine(file)
Next

Print ReadLine$( file )
Print number
MouseWait

CloseFile(file)

End

I've just tried it, and it seems to work ok for me

Hope that helps

------------------
Ty
~ I live to give

!▀rendan

Member

Posts: 21
From: Western Australia
Registered: 07-04-2002
Thanks Ty, your code worked well... I'm wondering if you would know how to wrap text when it gets to the edge of the window (and without breaking up the words) and/or how to use the code you posted to ready 3 lines with each random number...

eg 1=1st 3 lines 2=line 4+5+6 so on.

I guess it has something to do with this line of code. I'll keep trying to work it out for now.

for i=1 to number -1

------------------
-{!▀rendan}-

Ty

Member

Posts: 45
From: England
Registered: 05-15-2002
Hmmm, I did a word wrap code once, but I'll have to have a look in my code archive.

Recieving 3 lines is easy, just read 3 lines after the line gets instead of reading 1 line. I'll post he code when I have time to write and check it.

------------------
Ty
~ I live to give

!▀rendan

Member

Posts: 21
From: Western Australia
Registered: 07-04-2002
I think I know what your saying (I'm new to coding form HTML starit to Blitz Basic) I'll try it out... Code to wrap text would be very handy, thanks for your help.

------------------
-{!▀rendan}-