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 }
No. Use a loop and DATA segments.
Or: use 1D arrays and multiply the Y component yourself (that's what I do with SPRITE2MEM)
I'm very clumsy, could you give an example, Gernot?
Hi, you could fill the arrays also with a loop:
LOCAL array[]
DIM array[4][3]
FOR i=0 to 2
FOR j=0 to 3
array[i][j] = j
NEXT
NEXT
But I don´t know if this works for you. :)
cheers
That may help Charlie but not me. What I need is a quick way to fill the array with known values.
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?
LOCAL array%[]; DIMDATA array%[],1,2,3,4,1,2,3,4,1,2,3,4
LOCAL row%=1,column%=2
DEBUG array%[(row%*4)+column%]
Fantastic, very good solution. One-dimensional array used as a Multi-dimensional array.
Very clever. Thank you.
In these tilemap cases, it's just as neat to use DATA statements in GLB:
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,1
ENDDATA
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 :good:
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 :good:
I'm already happy, thanks. :whistle:
Maybe this should a feature that is implemented in a future version of GLBasic?