Addressing Arrays inside an Array
BlitzMax Forums/BlitzMax Beginners Area/Addressing Arrays inside an Array
| ||
I'm trying to bypass the fact you can't dynamically alter the size of multi-dimensional arrays: I have x-amount of array elements, each of which contains a sub-array with y-amount of elements. That works, but I don't know how to declare the variable that can hold a sub-array, in such a way that I can address it. Check the 'aRec' variable below for example; it will contain an object array, but doesn't allow me to define it as Local aRec:Object[] - or something. Any help much appreciated! SuperStrict Import brl.map Global nFields% = 4 Global nRecs% = 2 Global Data:Object[nFields] For Local i% = 0 To nFields -1 data[i] = New Object[nRecs] Next 'this returns an Object array to aRec (see debugger) Local aRec:Object = data[1] 'but I can't address any elements within that array: 'DebugLog aRec[1] 'is not valid DebugStop Cheers, Danny |
| ||
of course you can't access fields of type object because object is generic alpurpose that doesn't have any fields or functionality it is used for "storage" it is just used to accept any kind of object in to it self. if you want to access data in it, you got to convert it into the type that went in to it:arec:myType = myType(data[1]) you can't resize multi dimensional arrays but you can create arrays of arrays with as many dimensions as you want and they can be resized local data:int[][] data = data[..10] ' creates the first dimension 10 elements for local I:int = 0 until 10 ' creates the second dimension data[i] = data[i][..10] ' second dimension of ten elements each (an array of 10x10) next data[0][0] = 10 data[9][5] = 20 |
| ||
Thanks Jesse, that example got me back on the right track.. Cheers, D. |