GLBasic forum

Main forum => GLBasic - en => Topic started by: Sokurah on 2010-Sep-21

Title: How to clear a TYPE.
Post by: Sokurah on 2010-Sep-21
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?
Title: Re: How to clear a TYPE.
Post by: Bursar on 2010-Sep-21
If the aim is to delete all of the entities in the Type, then you could do:
Code (glbasic) Select

foreach enemy in EnemyTYPE[]
   delete enemy
next
Title: Re: How to clear a TYPE.
Post by: MrTAToad on 2010-Sep-21
A more efficient way would be :

Code (glbasic) Select
DIM EnemyType[0]

or

Code (glbasic) Select
REDIM EnemyType[0]
Title: Re: How to clear a TYPE.
Post by: Sokurah on 2010-Sep-21
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:
Title: Re: How to clear a TYPE.
Post by: Sokurah on 2010-Sep-21
Quote from: MrTAToad on 2010-Sep-21
A more efficient way would be :

Code (glbasic) Select
DIM EnemyType[0]

or

Code (glbasic) Select
REDIM EnemyType[0]

Would've been...if it worked. But it doesn't - I've tried.  ;)
Title: Re: How to clear a TYPE.
Post by: Ian Price on 2010-Sep-21
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.
Title: Re: How to clear a TYPE.
Post by: MrTAToad on 2010-Sep-21
Code (glbasic) Select
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:
Title: Re: How to clear a TYPE.
Post by: Kitty Hello on 2010-Sep-21
DIM -> also free up memory used. REDIM -> set counter to 0, keep intern memory to avoid lots or memory allocations.