reading position info from a txt
Blitz3D Forums/Blitz3D Programming/reading position info from a txt
| ||
hi, i wanted to know how one could save a x y z position in a text file then load the text file and read the x y z. Example : if i wanted to load 3 blocks blockxyz.txt block1 (0,34,90) block2 (20,48,2) block3 (38,77,1) how would i read that from blitz? |
| ||
Type Blocks Field x# field y# field z# end type ;If you don't pass a file name to the functions they will use a default file of blockpos.txt - you can change this to whatever you like function MakeBlockFile(Filename$="blockpos.txt") Blockfile=writefile(Filename$) if blockfile=0 then runtimeerror("Could not open " + filename$ + " for writing to.") count=0 for b.blocks=each blocks count=count+1 next writeline blockfile,count for b.blocks=each blocks writeline blockfile,b\x writeline blockfile,b\y writeline blockfile,b\z next closefile Blockfile end function then to read in the bloks you would have this... function GetBlocks(Filename$="blockpos.txt") Blockfile=readfile(Filename$) if blockfile<>0 then NumberofBlocks=readline(blockfile) For i=1 to NumberofBlocks b.blocks=new blocks b\x=readline(blockfile) b\y=readline(blockfile) b\z=readline(blockfile) next closefile Blockfile else runtimeerror("Block file:- "+filename$+ " does not exist") endif end function |
| ||
thanks, i'll give that a go. |