Redim an Array?

BlitzMax Forums/BlitzMax Beginners Area/Redim an Array?

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?

Check the documentation on Slicing

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:

Global TILESIZE:Int = 20
Global Height:Int = 100
Global Width:Int = 100

Global tiles:Int[Width/TILESIZE,Height/TILESIZE]
Print tiles[(width/TILESIZE)-1, (Height/TileSize)-1]
Height = 200
Width = 200
tiles = New Int[Width/TILESIZE,Height/TILESIZE]
Print tiles[(width/TILESIZE)-1, (Height/TileSize)-1]


Something:Blah = New Blah[size, size] ?

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.

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

...


Hmmm... I think I might have posted in invisible ink...

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.

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.

Perturbatio, use constansts instead of globals, faster :)

I know that already, but if tilesize needs to change, then constants are no use.