File Reading Problem
BlitzMax Forums/BlitzMax Beginners Area/File Reading Problem| 
 | ||
| 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.. | 
| 
 | ||
| That'll be ReadByte(file)  Unable to convert from 'Int(Tstream)' to 'Int' This almost always means you've forgotten a set of () somewhere. | 
| 
 | ||
| You missed MapData[databyte]=ReadByte(file) of course before mapdata:int[170*13] byez | 
| 
 | ||
| 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 | 
| 
 | ||
| . I forgot I had this page open for a while. :) | 
| 
 | ||
| Thanks all........... | 
| 
 | ||
| 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. | 
| 
 | ||
| You can either redeclare or dynmiacally increase/decrease the size of the array (slices). | 
| 
 | ||
| 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) |