Any way to change array dimension?
BlitzMax Forums/BlitzMax Beginners Area/Any way to change array dimension?
| ||
Say I have thisGlobal array$[1,20] and I want to change it to Global array$[20,20] How can that be done? |
| ||
Multi dimensional arrays post has an example of resizing an array of arrays (using slices) and a multi-dimensional array (using temp arrays). Baffled By Arrays explains the differences in possible arrays. |
| ||
Sorry, but there is no way to resize multidimensional arrays without loosing your data. Slicing only works for 1-dimonsional arrays. 'resizing 1-dim Array$[] = Array$[..newLenght] 'multi dim with loosing data Array$[,] = New String[20,20] There is a work around for this called 'Arrays in Arrays' There are some threads for this, just search a bit ;) |
| ||
I tried with a pointer but that didn't work either >.< |
| ||
Didn't the link I have help either? |
| ||
Haven't had time to try it, but I will :) |
| ||
You can't do array=array[[..20],[..20]] ? |
| ||
@Tonyg he wants a bespoke answer, not an off the peg link ;) |
| ||
I don't think so AngelDaniel. The purpose I'm using the array for is some x,y level data. Basically I do tilemap[10,11] to check what sort of tile exists there. The level must be of variable sizes, so one time the tilemap array could be [10,10], the next time it could be [100,15]. Oh wait, just thought of something heh, I guess it could work :) |
| ||
The level doesnt have to change size though does it? It just has to be one size, then for a NEW level a different size. So just kill the old one, and then make a new one. (When I say kill, I mean just point the array name to the new one) |
| ||
Just found the answer to my question :)local myarray[10,10] print myarray[9,9] myarray = new int[100,100] print myarray[99,99] |
| ||
1-dim solution, so: can be resized! mapdata[x+mapwidth*y]=mapdata Not what you want perhaps, but at least a semi-clean solution. |