TList

BlitzMax Forums/BlitzMax Beginners Area/TList

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

This I have found is the easiest way to emulate oldschool Blitz behaviour:
Type Vector2D
	Global _list:TList

	Field _x:Int	= 0
	Field _y:Int	= 0
	
	'
	' This adds a new Vector2D to the global list Vector2D._list
	Method New()
		If Vector2D._list = Null
			Vector2D._list = New TList
		EndIf
		Vector2D._list.addlast(Self)
	EndMethod
	
	'
	' Removes this instance from the list
	Method Destroy()
		Vector2D._list.remove(Self)
	EndMethod
	
	'
	' Removes all instances
	Function DestroyEach()
		Vector2D._list.clear()
	EndFunction
	
End Type

Graphics 640,480,0,0

MyVector2D:Vector2D = New Vector2D
MyVector2D._x = 50
MyVector2D._y = 70

MyVector2D:Vector2D = New Vector2D
MyVector2D._x = 10
MyVector2D._y = 90

While Not KeyHit(KEY_ESCAPE)

	'
	' A temporary Vector2D	
	MyVector2D:Vector2D = New Vector2D
	MyVector2D._x = Rand(100)
	MyVector2D._y = Rand(100)
	
	Render()

	'
	' Same as Delete MyVector2D in Blitz2D/3D/+
	MyVector2D.Destroy()

	FlushMem

Wend

'
' Same as Delete Each Vector2D in
Vector2D.DestroyEach()

End

Function Render()

	Cls

	DrawText "TEST",50,50
	
	Local p:Int = 0
	
	For MyVector2D:Vector2D = EachIn Vector2D._list
		DrawText MyVector2D._x,50, 80+p
		DrawText MyVector2D._y,50, 90+p
		
		p :+ 50
	Next
	
	Flip
		
End Function