File Reading Problem

BlitzMax Forums/BlitzMax Beginners Area/File Reading Problem

Mental Image(Posted 2006) [#1]
I have a file full of map data stored as bytes. I am trying to read it into a pre-defined array using this code:

	file=OpenStream("level1.dat") 
	If Not file RuntimeError "failed to open level1.dat file"
	databyte=0
	For x=0 To 170
		For y=0 To 12
			MapData[databyte]=ReadByte file
			databyte:+1
		Next
	Next
	
	CloseStream file


but get the following error:

"Compile Error
Unable to convert from 'Int(Tstream)' to 'Int'

Please help before I chuck the computer into the river..


FlameDuck(Posted 2006) [#2]
That'll be ReadByte(file)

Unable to convert from 'Int(Tstream)' to 'Int'
This almost always means you've forgotten a set of () somewhere.


degac(Posted 2006) [#3]
You missed
MapData[databyte]=ReadByte(file)


of course before


mapdata:int[170*13]


byez


tonyg(Posted 2006) [#4]
It would suggest your array is set-up as int.
Your readbyte command is also wrong...
Local mapdata:Byte[]
	file:TStream=OpenStream("level1.dat") 
	If Not file RuntimeError "failed to open level1.dat file"
	databyte=0
	For x=0 To 170
		For y=0 To 12
			MapData[databyte]=ReadByte(file)
			databyte:+1
		Next
	Next
	
	CloseStream file


I also changed file=openstream so file was TStream


Perturbatio(Posted 2006) [#5]
.

I forgot I had this page open for a while. :)


Mental Image(Posted 2006) [#6]
Thanks all...........


Mental Image(Posted 2006) [#7]
On a further subject, if I use this in a function, can I re-declare the size of the array based on the filesize of the particular file I want to load? Basically, I want to call the function usingthe pathname of the level data, and then set up my array based on the file size.


tonyg(Posted 2006) [#8]
You can either redeclare or dynmiacally increase/decrease the size of the array (slices).


Dreamora(Posted 2006) [#9]
You better declare the stream as file:TStream instead of int handle, thats faster (this holds for all objects where you can choose to use it)