DefData, ReadData... help.

BlitzMax Forums/BlitzMax Beginners Area/DefData, ReadData... help.


Basicly Im trying to access #map_main_data get 3rd/4th cell which is 10 to determine how many cells horizontal and then vertical #map_main_layer1 has.



This is how we used to do it in the old days:

SuperStrict						'SuperStrict mode: all variables' type and scope must be declared

Local rows:Int					
Local cols:Int

RestoreData map_main_layer1		'Move to the start of the "map_main_layer1" data block

ReadData rows					'Read the first data value and store it in "rows" variable
ReadData cols 					'Read the second data value and store it in "cols" variable

Local layer1:Int[rows, cols]	'Declare a two dimensional array to hold the remaining data

								'BlitzMax arrays start at zero so the maximum index value 
								'is always: dimension length - 1
For Local r:Int = 0 To rows - 1	

	Local test:String = ""		'DEBUG PURPOSES: Define a string to store a row
	
	For Local c:Int = 0 To cols - 1 
	
		ReadData layer1[r, c]	'Read in the next data value and store in the 
								'two dimensional array at index r,c
								
		test :+ layer1[r, c]	'DEBUG PURPOSES: Append the cell to the test string
								'"test :+" is shorthand for "test = test +" 
	Next
	
	Print test					'DEBUG PURPOSES: Print the row to the console
	
Next

End

#map_main_layer1				'Data block label
DefData 10, 10					'Number of rows, Number of columns
DefData 1,0,0,0,0,0,0,0,0,2		'Cell data: quantity of cells = (rows x columns)
DefData 0,3,0,0,0,1,0,0,0,0
DefData 0,0,0,0,0,0,0,0,0,0
DefData 0,0,0,1,0,0,0,0,0,0
DefData 0,0,0,0,0,0,0,0,0,0
DefData 0,0,0,0,0,0,0,0,0,0
DefData 0,0,8,0,4,0,0,0,0,0
DefData 0,0,0,0,0,0,0,0,0,0
DefData 0,0,0,0,0,0,0,0,0,0
DefData 0,9,0,0,0,0,0,0,0,4


EDIT: Added some comments to the code.