In BlitzMax I would normally clear a TYPE by doing so;
Enemies_list.Clear
...but how would I clear this one in GLBasic?
GLOBAL EnemyTYPE[] AS Enemies
Can it be done with one command like in Blitz?
If the aim is to delete all of the entities in the Type, then you could do:
foreach enemy in EnemyTYPE[]
delete enemy
next
A more efficient way would be :
DIM EnemyType[0]
or
REDIM EnemyType[0]
Thanks. I was hoping for a more elegant solution for initialising a level, as 20 loops like this is pretty messy. ;)
But it works. Thanks. :)
Aha. A new reply before I was done answering. I'll try that too, MrTAToad. :good:
Quote from: MrTAToad on 2010-Sep-21
A more efficient way would be :
DIM EnemyType[0]
or
REDIM EnemyType[0]
Would've been...if it worked. But it doesn't - I've tried. ;)
Dim EnemyTYPE[0] seems to work for me.
GLB is case-sensitive. Make sure your case matches, otherwise you are DIM'ing a new array.
TYPE tType
a%
ENDTYPE
LOCAL EnemyType[] AS tType; DIM EnemyType[20]
DEBUG BOUNDS(EnemyType[],0)+"\n"
DIM EnemyType[0]
DEBUG BOUNDS(EnemyType[],0)+"\n"
Result :
20
0
Works just fine :good:
DIM -> also free up memory used. REDIM -> set counter to 0, keep intern memory to avoid lots or memory allocations.