How to clear a TYPE.

Previous topic - Next topic

Sokurah

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?
Website: Tardis remakes / Mostly remakes of Arcade and ZX Spectrum games. All freeware. :-)
Twitter: Sokurah

Bursar

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

MrTAToad

A more efficient way would be :

Code (glbasic) Select
DIM EnemyType[0]

or

Code (glbasic) Select
REDIM EnemyType[0]

Sokurah

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:
Website: Tardis remakes / Mostly remakes of Arcade and ZX Spectrum games. All freeware. :-)
Twitter: Sokurah

Sokurah

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.  ;)
Website: Tardis remakes / Mostly remakes of Arcade and ZX Spectrum games. All freeware. :-)
Twitter: Sokurah

Ian Price

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.
I came. I saw. I played.

MrTAToad

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:

Kitty Hello

DIM -> also free up memory used. REDIM -> set counter to 0, keep intern memory to avoid lots or memory allocations.