Multidimensional array within type?

BlitzPlus Forums/BlitzPlus Programming/Multidimensional array within type?

sean916(Posted 2013) [#1]
Is it possible to store a multidimensional array within a type? If so what is the syntax for it?


Yasha(Posted 2013) [#2]
Not directly, no. The closest thing would be to have an array of array-objects that represent the second dimension.


fragfox(Posted 2013) [#3]
Ah, good idea. that should be a reasonably okay work around. Thanks!

Edit: this is the OP just noticed my laptop account is different from my desktop.


misth(Posted 2013) [#4]
You could also use memory banks if you want:

Graphics 800,600,32,2

Type Test
	Field w%,h%
	Field arr2D% ; this holds our "array"
End Type

Local t.Test = New Test

t\w = 20
t\h = 15
t\arr2D = CreateBank(t\w * t\h * 4) ; create bank, the "array"

; fill it with random data
For y = 0 To t\h - 1
	For x = 0 To t\w - 1
		offset = (x + y * t\w) * 4
		PokeInt t\arr2D, offset, Rand(255)
	Next 
Next

Repeat
	
	Cls
	
	; draw our data as tilemap
	For y = 0 To t\h - 1
		For x = 0 To t\w - 1
			offset = (x + y * t\w) * 4
			c = PeekInt(t\arr2D, offset)
			
			Color c,c,c
			Rect x*16, y*16, 16,16
		Next 
	Next
	
	; FPS, of course!
	Color 255,255,255
	Text 350,10,FPS()
	
	Flip
	
Until KeyDown(1)

; Delete stuff
FreeBank t\arr2D
Delete t

End

Global FPS_i, FPS_temp, FPS_time
Function FPS()
	ctime = MilliSecs()
	FPS_temp = FPS_temp + 1
	If ctime - FPS_time > 500 Then
		FPS_i = FPS_temp * 2
		FPS_temp = 0
		FPS_time = ctime
	EndIf
	Return FPS_i
End Function