Redim an Array?

BlitzMax Forums/BlitzMax Beginners Area/Redim an Array?

Saxon1974(Posted 2008) [#1]
Is there a way to redim an array in blitzmax? I have used it in other languages but Im not finding it here.

Basically I define this array when the program loads.

Global tiles:Int[GadgetWidth(MainCanvas.Tgad)/TILESIZE,GadgetHeight(MainCanvas.Tgad)/TILESIZE]

When the window gets resized it needs rerun or the array is the wrong size. Basically it just needs rerun after the resize of the window.

How would I do that?


Dreamora(Posted 2008) [#2]
Check the documentation on Slicing


Perturbatio(Posted 2008) [#3]
slices can only be done on single dimension arrays, however you can change it to be an array of arrays and then you can slice them.

*EDIT*
but you *should* be able to reassign the array variable to a new array:




Czar Flavius(Posted 2008) [#4]
Something:Blah = New Blah[size, size] ?


ImaginaryHuman(Posted 2008) [#5]
Local MyArray:Int[10]
Local MyArray2:Int[]=MyArray[..9]

To do multidimensional you have make a single dimensional array containing arrays and then slice each array.


TomToad(Posted 2008) [#6]
If you don't need to retain the old data, you can use the New command
Global tiles:Int[GadgetWidth(MainCanvas.Tgad)/TILESIZE,GadgetHeight(MainCanvas.Tgad)/TILESIZE]
...
Select EventID()
   Case EVENT_WINDOWSIZE
      'This will destroy the old data, so the array needs to be reloaded or reinitialized
      tiles = New Int[GadgetWidth(MainCanvas.Tgad)/TILESIZE,GadgetHeight(MainCanvas.Tgad)/TILESIZE]
End Select

...



Perturbatio(Posted 2008) [#7]
Hmmm... I think I might have posted in invisible ink...


tonyg(Posted 2008) [#8]
Sorry to double-guess but if this is some sort of tilemap can't you have the array the maximum height/width you will allow and display the tiles with a loop from a start_xpos for how many tiles will fit in the window.
If I have jumped the gun I apologise.


Perturbatio(Posted 2008) [#9]
Sorry to double-guess


I assumed it was for that too, but posited that it could also be for a tilemap editor that doesn't necessarily know the minimums and maximums.


Czar Flavius(Posted 2008) [#10]
Perturbatio, use constansts instead of globals, faster :)


Perturbatio(Posted 2008) [#11]
I know that already, but if tilesize needs to change, then constants are no use.