Didn't know this about arrays

Started by JBR, April 23, 2020, 01:30:12

Previous topic - Next topic

JBR


I have it declared as Global A_Jim[1024,2]

But it accepts A_Jim[23] = 999, say.

It puts the 999 in [23,1]

Took me a while to figure out as I expected it to throw an error but it does not.

Jim.

JBR

Quote from: JBR on April 23, 2020, 01:30:12

I have it declared as Global A_Jim[1024,2]

But it accepts A_Jim[23] = 999, say.

It puts the 999 in [23,1]

Took me a while to figure out as I expected it to throw an error but it does not.

Jim.

Correction it puts 999 in [11,1]

i.e. 11*2 + 1

_PJ_

A_Array[Z] = 999

It should fill the Zth "position" with a value of 999 as the data values are stored in memory in linear taking the dimensions of the array in rows then columns then layers etc.

For example:

A_Array:Int[] = New Int[X,Y,Z]

A_Array[(X * Y * Z) -1] = "1"
Will always set the last position to '1'

For Local Iter:Int = 0 Until Y
a[ Iter * (X-1) ]=1 Next
Would set the last entry in each column of the first layer's values to '1' as these positions in array are regularly spaced throughout the linear data by intervals of X

_

Personally, if opting for this method of data manipulation, I prefer to work with BANKS since it is essentially the same process, but may be faster.