Slices - What's wrong here?
BlitzMax Forums/BlitzMax Programming/Slices - What's wrong here?
| ||
I'm trying to resize a two dimensional array but I keep getting errors. None of the following work: Path = Path[..PathLength, 0..2] Path = Path[..PathLength, ..2] Path = Path[..PathLength, ..] |
| ||
if it would would you would do it like: path = path[..pathlength][..2] however you cant: Global path%[100,0] Global pathlength% = 100 Path = Path[..PathLength][..2] |
| ||
You cannot resize a two dimensional array using slices. Make a new array of the dimensions you need instead, and copy the old contents into the new one, and then assign the new to the old... Like this in pseudo code: local temp:Int[xlength,ylength] for x,y = all in old array temp[x,y] = old[x,y] next old = temp |
| ||
I don't think you can slice multidimensional arrays. Use arrays of arrays instead. [edit] ...eek...Miles too slow... [/edit] |
| ||
Bah. I tried making an array of arrays and I couldn't even get it to "invoke" the array, whatever that means. Thanks for the suggestion freadborg, but that's too messy/too much work. I'll just go with using two arrays one for X and one for Y, or simply use the multiply trick to make a 1D array 2D. Probably go for the first. Thanks! |
| ||
Im pretty sure this is how array o' arrays works.Local a:myObject[][] a = new myObject[][5] for i = 0 to 4 a[i] = new myObject[5] for j = 0 to 4 a[i][j] = new myObject next next 'slice both x and y to +1 a = a[..a.length+1] for i = 0 to a.length-1 a[i] = a[i][..a[i].length+1] next That's a lot of slicing for a large arrays. These are best used if your data wouldn't fill up a whole grid. Like this a[0] = {1,2,3} a[1] = {1,2,3,4,5,6,7} a[2] = {2} a[3] = {1,3,56,3312,17,98,111} |
| ||
http://www.blitzwiki.org/index.php/Arrays#Multi-Dimensional_Auto_Arrays |