Need algorithm!

Miscellaneous Forums/General Discussion/Need algorithm!

The array thing only works if each sprite has a specific index associated with it.


Is there something wrong with doing this?:
SuperStrict

Graphics 640,480,0

Type TSprite
	Global SpriteList:TList
	Global _IDCounter:Int = 0
	Field ID:Int
	Field X:Float
	Field Y:Float
	
	Function Create:TSprite(X:Float, Y:Float)
		If Not TList(SpriteList) Then SpriteList = New TList
		Local tempSprite:TSprite = New TSprite
			tempSprite.X = X
			tempSprite.Y = Y
			tempSprite.ID = GetUniqueID()
			SpriteList.AddLast(tempSprite)
		Return tempSprite
	End Function
	
	
	Function GetUniqueID:Int()
		Local result:Int
			result = _IDCounter
			_IDCounter:+1
		Return result
	End Function
End Type


For Local i:Int = 0 To 100
	Local tempSprite:TSprite = TSprite.Create(RndFloat()*640, RndFloat()*480)
Next


While Not KeyDown(KEY_ESCAPE)

	For Local s:TSprite = EachIn TSprite.SpriteList
		DrawText(s.ID, s.X, s.Y)
	Next
	
	Flip
	Cls
Wend


GCCollect()

End



Then they all have unique ID's automagically assigned to them without the user needing to know anything about it.