Array exeption in two lines...
BlitzMax Forums/BlitzMax Beginners Area/Array exeption in two lines... You can do what you want, but the initialisation is a bit
more complicated. I guess an array initialiser only initialises one array per command.
I'll leave it as an exercise for the reader to extrapolate to 3D. I wouldn't bother with arrays of arrays unless you have a specific reason. Multidimensional arrays are less of a headache.
more complicated. I guess an array initialiser only initialises one array per command.
Local earth2:Int[][] earth2=New Int[] [2] For n=0 To 1 earth2[n]=New Int [2] Next earth2[1][1] = 1 DebugLog earth2[1][1]
I'll leave it as an exercise for the reader to extrapolate to 3D. I wouldn't bother with arrays of arrays unless you have a specific reason. Multidimensional arrays are less of a headache.
Basically, i wanted to see if it was possible to work with arrays without having to set up the size.
Arrays of arrays seemed to be a more logical way to do things, but i think multidimentional arrays are easier to use :)
Edit, sorry for my bad english, i try to do my best.
Edit2:
Ok, fully understood how to use array of arrays, i guess there is no way to create arrays without setting up their initial size.
Arrays of arrays seemed to be a more logical way to do things, but i think multidimentional arrays are easier to use :)
Edit, sorry for my bad english, i try to do my best.
Edit2:
Local earth2:Int[][] earth2=New Int[] [2] For n=0 To 1 earth2[n]=New Int [2] Next earth2[1][1] = 1 DebugLog earth2[1][1]
Ok, fully understood how to use array of arrays, i guess there is no way to create arrays without setting up their initial size.
I tried to init a multidimentional array a while back but it can't be done. You have to manually do it, sorry.
Basically, i wanted to see if it was possible to work with arrays without having to set up the size.
It isn't. An Array, by definition, always has a known size. Depending on what you're trying to achieve, try using Lists or Graphs instead. Your help was really apprecied, it allowed me to define things without making the compiler angry.
the following is just some training i wanted to do, could allow me to create selfmade strange things :)
Just to show you its correctly eaten by the compilater.
the following is just some training i wanted to do, could allow me to create selfmade strange things :)
Just to show you its correctly eaten by the compilater.
Global Xindex:Int=0 Global X:Int[][][][] Function createXarray() X=New Int[][][] [10] X[Xindex] = createX(2, 2, 2, 0, 0, 0, 2, 2, 2); X[Xindex] = createX(2, 2, 2, 0, 2, 0, 2, 2, 2); X[Xindex] = createX(2, 2, 2, 0, 0, 0, 2, 2, 2); X[Xindex] = createX(1, 1, 1, 1, 1, 1, 0, 0, 0); X[Xindex] = createX(1, 1, 1, 1, 2, 1, 0, 0, 0); X[Xindex] = createX(1, 1, 1, 1, 1, 1, 0, 0, 0); X[Xindex] = createX(0, 0, 0, 2, 2, 2, 0, 0, 0); X[Xindex] = createX(0, 0, 0, 2, 0, 2, 0, 0, 0); X[Xindex] = createX(0, 0, 0, 2, 2, 2, 0, 0, 0); X[Xindex] = createX(0, 0, 0, 0, 0, 0, 0, 0, 0); End Function Function createX:Int[][][](a:Int, b:Int, c:Int, d:Int, e:Int, f:Int, g:Int, h:Int, i:Int) Local rArray:Int[][][]=New Int[][][4] rArray[0] = [[a,b,c], [d,e,f], [g,h,i]]; rArray[1] = [[d,e,f], [g,h,i], [a,b,c]]; rArray[2] = [[a,b,c], [g,h,i], [d,e,f]]; rArray[3] = [[g,h,i], [d,e,f], [a,b,c]]; Xindex=Xindex+1 Return rArray; End Function
you can init a blank multi dimensional array on the run:
what you can not do is resize it and keep the data. but I am shure a work around can be easily implemented.
Global array:Int[,,] array = Createarray(10,10,10) Print array.length array = createarray(20,20,20) Print array.length Function createarray:Int[,,](x:Int, y:Int, z:Int) Return New Int[x,y,z] End Function
what you can not do is resize it and keep the data. but I am shure a work around can be easily implemented.