How to create array of arrays of objects?
BlitzMax Forums/BlitzMax Beginners Area/How to create array of arrays of objects?
| ||
Hai Yall If I uncomment the third line I get all kind of errors. The rest of the code slices the array?, while I want to create a new (empty) one. And further up add new arrays of object to the "Main"-array. How? (Howl!) And.. how can I find this stuff out without asking you guys? |
| ||
Hello there, It would seem that Blitzmax internal documentation is bit lacking in this department, but I think this might be helpfull Click here! Also slicing an array actually creates a new array with given dimensions and copies old elements to this new array. -Henri |
| ||
Thank Henri Alas, my problem is not how to create an array of arrays. But of an array of object-arrays. This code achieves more or less what I want, but the first "dimension" is not removed by just :(arrayOfArray = arrayOfArray [..10]), but by also doing :(arrayOfArray = arrayOfArray [..0] ) I know slicing is less fast than creating a new array. Plus, I want to make 'sure' it's empty. (now how to do this correctly?) cheers! ( where are my pajamas ?) Last edited 2012 |
| ||
when you create the array, it's created as an array of null objects. So you have to assign each of the elements an object [bbcode] if arrayofArrays[0][0] = null arrayOfArray[0][0] = new TTile End if [/bbcode] |
| ||
It's not clear just what you are trying to accomplish. But it involves two concepts. The first is slicing applied to an array of arrays. The second is dealing with arrays of objects. Maybe this example will clear up the slicing. It uses integers for simplicity. Local a[][] = [ [1,2,3], [4,5,6,7] ] ' Now a is an array with two elements. The first element a[0] is the array [1,2,3]. ' Let's view the second element. Print t$ = "" count = 0 For n = EachIn a[1] t :+ n + " " count :+ 1 Next Print "Elements of a[1] are " + t Print "There were " + count + " of them." ' Now slice a, keeping only one element. a = a[..1] Print t$ = "" count = 0 For n = EachIn a[0] ' Same thing with a[1] would fail because it no longer exists. t :+ n + " " count :+ 1 Next Print "Elements of a[0] are " + t Print "There were " + count + " of them." ' Finally, let's slice a[0], discarding the first element and adding two more. a[0] = a[0][1..5] Print t$ = "" count = 0 For n = EachIn a[0] ' Same thing with a[1] would fail because it no longer exists. t :+ n + " " count :+ 1 Next Print "Elements of a[0] are " + t Print "There were " + count + " of them." |
| ||
@Both : Thanks When I posted my question last night, I had spend 3 hours of trying all kind of syntax-combinations I could thing of. So I think I was not quite clear about describing the actual problem. I know how to use slicing on an arrays of arrays. But in this case I don't want to, because it is slow and doesn't clear the array. I want to redefine the array. Not resize it. After another two hours of boggling, I came up with this: I guess this is the way to do it. [Edit] I changed "multidimensional" to "array of arrays" [/edit] Last edited 2012 |
| ||
If you have no interest in resizing the array, why not use multidimensional arrays instead? SuperStrict Local arrayOfArray:Object[,] arrayOfArray =New Object[10,10] arrayOfArray[0,0]="Test" Print String(arrayOfArray[0,0]) arrayOfArray =New Object[10,10] Print String(arrayOfArray[0,0]) |
| ||
Well; keep in mind that this example,(as most examples) is meant to be a summary of a more complex problem. In this case I want to add or delete arrays from the main-array, or substitute them with other lengths. (I guess that could also be called "resizing", but this way it is also certain that the "resized" array is empty.(and this is much faster) Last edited 2012 Last edited 2011 Last edited 2012 |