Q1: best way to cleanup types?

Blitz3D Forums/Blitz3D Beginners Area/Q1: best way to cleanup types?

It can be handy to write functions to do this, like this:

Type SPRITE
   Field f_image
End Type

Function SPRITE_delete(p_sprite.SPRITE)
   FreeImage(p_sprite\f_image)
   Delete(p_sprite)
End Function

Function SPRITE_deleteAll()
   For sprite.SPRITE = Each SPRITE
      SPRITE_delete(sprite)
   Next
End Function

; at the end of your program or level you can now say:

SPRITE_deleteAll()


This may look like extra work, but when you do it like this you assure that what needs to be done is done (when you put it in the function) upon deletion of an object. For instance, suppose you want to keep track of the number of sprites objects. You could add an extra line to the delete function like this:

; suppose this is the global sprite counter
g_spriteCounter = 0

Function SPRITE_delete(p_sprite.SPRITE)
   FreeImage(p_sprite\f_image)
   Delete(p_sprite)
   g_spriteCounter = g_spriteCounter - 1
End Function