Array

BlitzMax Forums/BlitzMax Beginners Area/Array

This example, is a simplified form of what I was finally able to use in the map editor that I created for my program. I think it might help beginners like me to organize their mind and their codes - at least to begin with.

Here are two classes. In the second one there is a 2d array. Notice the way the array is objectified, and needs necessarly to do so. I learned this from FlameDuck (the code above) and have applied it the way you can see. Unfortuanely, [..100] doesn't work for 2d arrays. So, for dynamic array, we need few more functions that one day I may code it and show it.

SuperStrict
'//////////////////////////
Type report_cells

	Field a:Int=0
	Field b:String=""
	
	Method Print_BlitzMax()
		For Local i:Int=0 To 7
			Print "report_content method works"
		Next
	End Method
	
End Type

'/////////////////////////////
Type report_table

	Field column:Int=6
	Field row:Int=6
	Field table:report_cells[column,row]
	
End Type
'//////////////////////////////


Local the_report:report_table=New report_table

For Local m:Int=0 To the_report.column-1
		For Local n:Int=0 To the_report.row-1
			
			the_report.table[m,n] = New report_cells
			
		Next
Next

For Local m:Int=0 To the_report.column-1
		For Local n:Int=0 To the_report.row-1
			report_cells(the_report.table[m,n]).a=12
			report_cells(the_report.table[m,n]).b="hi there!"
			
		Next
Next

Print report_cells(the_report.table[1,1]).a
Print report_cells(the_report.table[0,0]).b
Print report_cells(the_report.table[2,3]).b
Print report_cells(the_report.table[1,4]).a
Print report_cells(the_report.table[3,2]).b
Print report_cells(the_report.table[2,3]).b