GetElementsByType()

BlitzMax Forums/BlitzMax Programming/GetElementsByType()

Hello,

I have a quite familiar object structure in my game (don't worry, example code is provided below):

TElement type
TPlayer extends TElement
TEnemy extends TElement
TBullet extends TElement

TElement controls a global list with all created TElements

Now I want to write a TElement method GetElementsByType:TList(typeID) to receive all elements of that type.

Example:
Type TElement
	Global golElements:TList = CreateList()

	Method New()
		golElements.AddLast(Self)
	End Method
	
	'this function does not work. It's an example of what I want
	Function GetElementsByType:TList(typeID)  ' if typeID:TTypeID, how do you call this method?
		Local oElements:TList = CreateList()
		For Local o:typeID = EachIn golElements
			oElements.AddLast(o)
		Next
		Return oElements
	End Function
End Type

Type TPlayer Extends TElement
	'.. create function etc.
End Type

Type TEnemy Extends TElement
	'.. create function etc.
End Type

Type TBullet Extends TElement
	'.. create function etc.
End Type


'receive all bullets:
Local olBullets:TList = TElement.GetElementsByType(TBullet)


I can write a function for every extended type, like
TElement.GetBullets()
TElement.GetEnemies()
but I would like to have a generic function where I can call every extended type without writing a function for each and every extended type.

Is there a way to do this?