Reading from a file

Blitz3D Forums/Blitz3D Programming/Reading from a file

cash(Posted 2005) [#1]
I have been looking at the CSP Game engine plus a few others and like the idea of reading from a file to place objects in the 3d world on startup.

is it easy to read a file into blitz like this.


Rob Farley(Posted 2005) [#2]
yes

filein = readfile("goat.txt")

repeat
a$ = readline(filein)

; do stuff with a$

until eof(filein)
closefile(filein)



cash(Posted 2005) [#3]
okay so;

I create a text file called test.txt with one line in in it model1.b3d
call it in blitz as above
I want for example a$ to be a global variable which is a model called "model1.b3d"

I cant get it to work. Am I asking too much ?


cash(Posted 2005) [#4]
okay I think I figured it.

call the file
using separate string variables

global v1=a$

v1=loadmesh(etc)

Sort of works need some tweeking


Ross C(Posted 2005) [#5]
Well, you txt file would contain say:

"models\gun.b3d"
"models\player.b3d"
"models\crate.b3d"

and you would load them into strings:

a$ = readline() ; what ever the stream name is

(a$ would = "models\gun.b3d")

temp = loadmesh(a$)


Something like that. Just basically make sure the code you use to load your file, is laided out the same way as the code so save it.