## News:

*NEW* Current Version on STEAM16.793

Webchat:
Visit the chat

## Multi-Dimensional Array Question

#### Charlie

is it possible to declare multi-dimensional arrays in glbasic like in other languages such as:

array[4][3] = { 1,2,3,4,
1,2,3,4,
1,2,3,4 }

#### Kitty Hello

No. Use a loop and DATA segments.
Or: use 1D arrays and multiply the Y component yourself (that's what I do with SPRITE2MEM)

#### msx

I'm very clumsy, could you give an example, Gernot?

#### backslider

Hi, you could fill the arrays also with a loop:

Code (glbasic) Select
`LOCAL array[]DIM array[4][3]FOR i=0 to 2    FOR j=0 to 3        array[i][j] = j    NEXTNEXT`

But I don´t know if this works for you.

cheers

#### msx

That may help Charlie but not me. What I need is a quick way to fill the array with known values​​.

#### Charlie

my reason for using arrays this way was for a "visual" for using tile maps. That way you can see a visual of your map using image numbers.
Most languages can do this with arrays.

Example:
image 1 = grass 2 = dirt

array[5][5] = {
1,2,1,1,1
1,2,1,1,1
1,2,2,2,2
1,1,1,1,1
1,1,1,1,1
}

Quote from: msx on 2011-May-27
I'm very clumsy, could you give an example, Gernot?
Code (glbasic) Select
`LOCAL array%[]; DIMDATA array%[],1,2,3,4,1,2,3,4,1,2,3,4LOCAL row%=1,column%=2DEBUG array%[(row%*4)+column%]`

#### msx

#7
Fantastic, very good solution. One-dimensional array used as a Multi-dimensional array.

Very clever. Thank you.

#### Moebius

#8
In these tilemap cases, it's just as neat to use DATA statements in GLB:
Code (glbasic) Select
`STARTDATA Level1:    DATA   1,2,1,1,1    DATA   1,2,1,1,1    DATA   1,2,2,2,2    DATA   1,1,1,1,1    DATA   1,1,1,1,1ENDDATA`
If you really want a multidimensional "DIMDATA", then submit a feature request, if you think it's more important than finishing off polishing Android support
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
- Random Shack Data Processing Dictionary

#### msx

Quote from: Serpent on 2011-May-27
If you really want a multidimensional "DIMDATA", then submit a feature request, if you think it's more important than finishing off Android support