GLBasic forum

Main forum => GLBasic - en => Topic started by: Gary on 2009-Oct-22

Title: dimdata question
Post by: Gary on 2009-Oct-22
Is there a simple way im missing if using DIMDATA on a 2 dimensional array? From the manual it seems to only work on single dimensions


Thanks
Gary
Title: Re: dimdata question
Post by: Foo on 2009-Oct-22
I would say no - but I would do it this way:
Code (glbasic) Select
DIMDATA fieldSet1[], 1,4,5,6
DIMDATA fieldSet2[], 4,5,5,7
DIM realfield[2]
realfield[0] = fieldSet1
realfield[1] = fieldSet2
Title: Re: dimdata question
Post by: Moru on 2009-Oct-22
a twodimensional array is realy just a bunch of numbers, you decide how you store them. When you read them you just read the first 5 into your first row of the array, then you read the next 5 numbers into the second row and so on until the array is filled or the data is out.

Let me know if you want more specific help :-)
Title: Re: dimdata question
Post by: Kitty Hello on 2009-Oct-22
Quote from: Foo on 2009-Oct-22
I would say no - but I would do it this way:
Code (glbasic) Select
DIMDATA fieldSet1[], 1,4,5,6
DIMDATA fieldSet2[], 4,5,5,7
DIM realfield[2]
realfield[0] = fieldSet1
realfield[1] = fieldSet2


DOES THAT WORK !?

[edit]
No, it doesn't!

You have to make a loop where you enter tha values. Just read from a file or a DATA block.
Title: Re: dimdata question
Post by: Gary on 2009-Oct-22
In c I would do something like

Code (glbasic) Select

const unsigned  char fruit_prob[3][32]= {{6,6,6,6,6,6,6,6,6,6,6,6,8,8,8,8,8,8,8,8,0,0,0,0,0,0,1,1,1,1,1,1},
{2,2,2,2,2,2,6,6,6,6,6,6,8,8,8,8,8,8,8,8,0,0,0,0,0,0,1,1,1,1,1,1},
{6,6,6,6,6,6,6,6,6,6,6,8,8,8,8,8,8,8,8,0,0,0,0,0,0,1,1,1,1,1,1,1}};


thats the kind of thing that if possible to be done with DIMDATA

Thanks
Gary
Title: Re: dimdata question
Post by: Kitty Hello on 2009-Oct-22
it's not possible. DIMDATA ist just a quicky for 1D arrays.
use that:

Code (glbasic) Select

RESTORE foo
READ w, h
DIM arr[w][h]
FOR y=0 TO w-1
FOR x=0 TO h-1
READ arr[x][y]
NEXT
NEXT


STARTDATA foo:
DATA 4,2 // width, height
DATA 1,2,3,4
DATA 5,6,7,8
ENDDATA