reading files

Blitz3D Forums/Blitz3D Beginners Area/reading files

David819(Posted 2003) [#1]
Hi i am trying to make a program to open a .dat file but cant get the files and folders inside to show please help.


cbmeeks(Posted 2003) [#2]
can you post some code so we can see what is wrong?

cb


David819(Posted 2003) [#3]
Graphics3D 640,480
SetBuffer BackBuffer()

camera=CreateCamera()
CameraViewport camera,320,0,320,240

;open oni dat file
file = ReadFile("level1_Final.dat")
Name$ = ReadString$( file )
extension = ReadInt( file )
other = ReadByte( file )
Write "Name = "
Print Name
Write "extension = "
Print extension
Write "other = "
Print other




While Not KeyHit(1)

If KeyDown(203) MoveEntity pivot,-.1,0,0
If KeyDown(205) MoveEntity pivot,.1,0,0
If KeyDown(200) MoveEntity pivot,0,.1,0
If KeyDown(208) MoveEntity pivot,0,-.1,0
If KeyDown(30) MoveEntity pivot,0,0,.1
If KeyDown(44) MoveEntity pivot,0,0,-.1


UpdateWorld
RenderWorld
Text 320,0,"3D Viewer"
Flip

Wend

End

This is my crappy code so far, lol.


semar(Posted 2003) [#4]
Goober,
you read the info you need from the file, assuming that the file contains the values - strings, integers, bytes - in the right order.

The info you read, you want to be displayed at each main loop, right ?

The problem in your code, is that you print the text just before the main loop, and then, in the main loop is cleared from the UpdateWorld command, because this command clears the screen too.

So you should:
- before the main loop, read the data from the file, as you already do, and close the file
- in your main loop, where you write "3D Wiever", you should also print out the data you need:

.
updateworld
renderworld
text 320,0,"3D Wiever"

Write "Name = " 
Print Name 
Write "extension = " 
Print extension 
Write "other = " 
Print other 

flip


Note that the print command slows down the loop, so I would strongly suggest to use Text instead.

More, make a function that prints (using the text command !) the info out, so you would have a more readable main loop, instead of a loads of statements:

;main loop
updateworld
renderworld
print_info()
flip


Bare in mind that if you make a function and call it from the main loop, then the variable that you use (name, extension, others...) should be declared Global.

Hope this has sense for you,
Sergio.


David819(Posted 2003) [#5]
Still doesn't work the file im trying to get stuff out of is in .dat form iside that file is animation, 3d characters, sounds and such but i do not know how to get to those files.


eBusiness(Posted 2003) [#6]
Your info is written, but you'll newer see, as program immediately goes on and do a RenderWorld. Make Waitkey() after print other.