Extended Types and Global Lists

BlitzMax Forums/BlitzMax Beginners Area/Extended Types and Global Lists

I'd do it like this:
Type A
	
	Global List:TList
	
	Field Test:Byte
	Field letter:String
	
	Method New()
		
		If List=Null Then List = New TList
		List.AddLast Self
		
		self.test = Rand(0,255)
		self.letter = "A"
		
	End Method
	
	
End Type


Type B Extends A

	Global List:TList
		
	Method New()
		If List=Null Then List = New TList
		List.AddLast Self
		self.letter = "B"
	EndMethod
	
End Type


Type C Extends A

	Global List:TList
	
	Method New()
		If List=Null Then List = New TList
		List.AddLast Self
		self.letter = "C"
	EndMethod
	
End Type


Global AB=New B
Global BB=New B
Global CB=New B

Global AC=New C
Global BC=New C
Global CC=New C

' List all types
Print "A,B, and C"
For allTypes:A = EachIn a.List
	Print allTypes.letter+","+allTypes.Test
Next
Print "~n"

' List all B types
Print "Only Bs"
For bTypes:B = EachIn b.List
	Print bTypes.letter+","+bTypes.Test
Next
Print "~n"

' List all C types
Print "Only Cs"
For cTypes:B = EachIn c.List
	Print cTypes.letter+","+cTypes.Test
Next
Print "~n"