Any way to change array dimension?

BlitzMax Forums/BlitzMax Beginners Area/Any way to change array dimension?

kronholm(Posted 2007) [#1]
Say I have this

Global array$[1,20]


and I want to change it to

Global array$[20,20]


How can that be done?


tonyg(Posted 2007) [#2]
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.


klepto2(Posted 2007) [#3]
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 ;)


kronholm(Posted 2007) [#4]
I tried with a pointer but that didn't work either >.<


tonyg(Posted 2007) [#5]
Didn't the link I have help either?


kronholm(Posted 2007) [#6]
Haven't had time to try it, but I will :)


ImaginaryHuman(Posted 2007) [#7]
You can't do array=array[[..20],[..20]] ?


H&K(Posted 2007) [#8]
@Tonyg he wants a bespoke answer, not an off the peg link ;)


kronholm(Posted 2007) [#9]
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 :)


H&K(Posted 2007) [#10]
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)


kronholm(Posted 2007) [#11]
Just found the answer to my question :)

local myarray[10,10]

print myarray[9,9]

myarray = new int[100,100]

print myarray[99,99]



CS_TBL(Posted 2007) [#12]
1-dim solution, so: can be resized!

mapdata[x+mapwidth*y]=mapdata

Not what you want perhaps, but at least a semi-clean solution.