Going through types..

BlitzMax Forums/BlitzMax Programming/Going through types..

The Forum Archive is locked. These are the original blitzbasic.com forums, kept so their posts can still be read and searched. No new topics, replies or edits can be made here. To join the conversation, head over to the Blitz3D+ forums.

Will it hurt to put Global MyTestList:TList = CreateList() inside of the type declaration?

No. Lots of people do it that way. I don't do it because I find it more readable to do it elsewhere, but there's nothing wrong with your method. You can put a MyTestList.AddLast(Self) in the New() method so that it's called automatically on object creation if you like.

And, can i get an example for removing the objects from the list when i delete the type?

You can't delete objects. They are deleted automatically when they go out of scope, and they won't go out of scope all the time they're in the list.

To get something similar to B3D type usage, try something like this :

Type MyType

   Global List:TList
   Field Link:TLink

   Method New()
      If List=Null
         List=New TList
      End If
      Link=List.AddLast(Self)
   End Method
   
   Method Destroy()
      Link.Remove()
   End Method
End Type


Keeping the TLink returned by the AddLast() method saves you looking through the list when you want to destroy it. Keep in mind, however, that your Destroy() method will only work if there are no other references to your object. If you add it to other lists, or put it in the fields of other objects ( parents/children for example ) then you will need to nullify those reference in your Destroy() method as well.