Can I make arrays for type fields?

Blitz3D Forums/Blitz3D Programming/Can I make arrays for type fields?

OrcSlayer(Posted 2004) [#1]
I'm pretty good at using types, but I have never tried making one of the field values an array. I've done something very similar in other languages...I assume it's possible in Blitz?

This will come in very handy since I'm currently coding my custom anim-sprite type, and I will absolutely need it for player inventory soon...


Aymes(Posted 2004) [#2]
I think its an undocumented feature of blitz but ive used arrays in types like this...

type my_type
field my_array[20]
end type

im pretty sure you can only do one dimensional arrays tho, unless anyone knows different?


OrcSlayer(Posted 2004) [#3]
Thanks! That will help tremendously...

Hmmm, I remember in one of the languages I used creating an array with a value of -1 meant it was dynamic...Does Blitz have anything similar?


Almo(Posted 2004) [#4]
You can even make fields arrays of types! Very nice...

Const ASDNumAllowedCollisions = 20
Const ASDNumOffsetLayers = 10
Const ASDNumSprites = 100
Const ASDNumTexts = 10
Const ASDDebug = 1	; 0 to remove debug messages
										; 1 for debug messages

Type AlmoSpriteDriver
Field BackgroundImage ; Expects handle to be in upper-left corner
Field BGOffsetLayer
Field CLSEachFrame
Field DefaultFont ; after calling ASDUpdate, this font will be the Text-ing font
									; specify -1 (the default) and ASD will leave the Text-ing font the
									; same as that of the last drawn Text.
Field DrawBG
Field OffsetLayers.ASDOffsetThing[ASDNumOffsetLayers]
Field Sprites.ASDSprite[ASDNumSprites]
Field Texts.ASDText[ASDNumTexts]
Field Initialized
End Type

Type ASDOffsetThing
Field x#, y#
End Type

Type ASDSprite
Field Image
Field x#, y#
Field Active 		; 0 - sprite is inactive, doesn't do anything
								; 1 - sprite is active, draws, etc.
Field Collides  ; -1 - sprite doesn't collide
								; 0 - sprite collides with all other sprites with Collides >= 0
								; >= 1 - sprite collides with all other sprites with same Collides value
								;    and those with Collides = 0
Field OffsetLayer
Field Collided[ASDNumAllowedCollisions]	; max allowed collisions a sprite will store.
				; subsequent collisions ignored
Field NumCollisions	; indicates number of collisions this frame
End Type

Type ASDText
Field theText$
Field x, y
Field CenterX, CenterY
Field OffsetLayer
Field Active		; 0 or 1, whether to draw or not
Field OnTop			; 0 or 1, whether it shows up on top of other sprites
Field theColorR, theColorG, theColorB		; color of text
Field Font
End Type

; end typedefs


And normal blitz arrays ARE dynamic, you just redim them. But field arrays are not dynamic, and must have a known size at compile time. So

;BROKEN CODE
global typesize = 20
type mytype
field thefield[typesize]
end type
;END BROKEN CODE


Will not work.
But
const typesize = 20
type mytype
field thefield[typesize]
end type


Will work since typesize is const, and is therefore known at compile time.


Genexi2(Posted 2004) [#5]
Here's a little piece of code Seth posted on the other forum to fake multi-dimenstional arrays in a type field with a one-dimensional array. : http://www.blitzcoder.com/cgi-bin/ubb-cgi/postdisplay.cgi?forum=Forum14&topic=000800


OrcSlayer(Posted 2004) [#6]
Well, I guess that means I'll have to make a good set value and scan through it with a for...next loop to see which values are not null...

Thanks for the help!