Arrays...

Blitz3D Forums/Blitz3D Beginners Area/Arrays...

I'v been reading some good C++ books, and arrays seem very handy, i'v never messed with them in blitz, but as a learning thing i'd like to use them as a data stucture...

I want a multi-dimensional array so i can create a data structure like this:

myarray[
"test",100,
"secondtest",200,
]

to have 2 elements for an array... is this kind of stuff possible in blitz? or should i go with my usual TYPES data structure? (harder to type and harder to read then somthing like the above)

As far as I'm aware the nearest to this in Blitz would be types.

In C you usually use typedef struct and then have an array of the associated structure.

In the blitz manual you can use the dim command

e.g Dim (100,200)

From my understanding the Dim command only creates an array of a single type. eg. Dim name$(10,5,2) creates an array of strings, despite how many dimensions are specified.

In C you can define a custom structure and create and array from that structure. eg.


typedef struct my_array
{
    int a
    float b
    char c
} MY_ARRAY;

then use it as follows:

const MY_ARRAY  array[]=
{
     { 1, 2.5, 'a' },
     { 6, 7.5, 'b' },
     { 2, 3.2, 'c' },
     { 4, 1.2, 'd' }
};



In Blitz you can also have an array of types:
Type Planet
field name$
field radius%
end type

Dim MyArray.Planet(10) ; or MyArray(10).Planet, I can't remember now the syntax.
MyArray(1) = new Planet
MyArray(1)\radius = 123
MyArray(1)\name = "Saturn"

;another use is also:
p.Planet = MyArray(1)
print "Planet " + p\name + " has a radius of " + p\radius + " Km."


Sergio.

Thanks for the help guys, but its easyer for me just to use TYPES