type and dim ?

Blitz3D Forums/Blitz3D Programming/type and dim ?

Duckstab[o](Posted 2005) [#1]
is it possible to create a dim of a type within another type

ie

type mapsector
field x
field y
ect
ect
end type

type map
field a.mapsector[10,10]
end type


DJWoodgate(Posted 2005) [#2]
Yes, but [] arrays can only have a single dimension.


Duckstab[o](Posted 2005) [#3]
any code snippits to show this in action would be a blessing :)


SoggyP(Posted 2005) [#4]
Greetings Puppies,

Here you go, if you need it explained just ask.


Peace,

Jes


Techlord(Posted 2005) [#5]
Duckstab[o],

Its true that Blitz Type Arrays can only have 1 dimension:
type mapsector 
field x 
field y 
ect 
ect 
end type 

type map 
field a.mapsector[10] 
end type 

mymap.map = new map
mymap\a[1]=new mapsector
mymap\a[2]=new mapsector

mymap\a[1]\x=10
mymap\a[1]\y=100

print mymap\a[1]\y
However, there is very simple algorithm used by many compilers to calcuate the linear index of multi dimensional arrays. You can apply the formula yourself. One way or another this math is applied.

If your ready for the challenge you can also create an array of types.
dim maparray.map(10) ;notice the parenthesis '(' & ')'
maparray(1)=new map
maparray(1)\a[1]=new mapsector
maparray(1)\a[1]\y=10
print maparray(1)\a[1]\y
You can also do this:
global staticarray.map[100]; notice the 'global keyword and '[' & ']' brackets.
staticarray[4] = New map
staticarray[4]\a[1]=New mapsector
staticarray[4]\a[1]\x=21
Print staticarray[4]\a[1]\x
This difference between them is that you cannot redim a staticarray and its limited to 1 dimension.


Duckstab[o](Posted 2005) [#6]
thanks Djwoodgate,Soggp,Frank Taylor thats hopefully enough to get me
started


Duckstab[o](Posted 2005) [#7]
What about Multi Dimensional arrays of type arrays do they have any speed issue and limitations

Type Box
	Field Value[10]
	Field Spritr_id
	Field Active
	Field x
	Field z
End Type
Dim Grid.box(10,10)

Grid.box(1,1)=New box
grid(1,1)\value[1]=10
Grid.box(1,2)=New box
grid(1,2)\value[1]=30
Print grid(1,1)\value[1]
Print grid(1,2)\value[1]