Anyone have any examples using FindLink?

BlitzMax Forums/BlitzMax Programming/Anyone have any examples using FindLink?

JoJo(Posted 2005) [#1]
I have 20 objects in a list. And instead of looping thru the objects using the For...Each loop, I want to just
find a particular object using either the FindLink method, or ValueAtIndex method or maybe the Contains method.

I search the docs but couldn't find an example.


skn3(Posted 2005) [#2]
Example of using FindLink
Local list:Tlist = CreateList()

Type mytype
	Field id
	Method New()
		id = Rand(0,255)
	End Method
End Type

Local m1:mytype = New mytype; list.AddLast(m1)
Local m2:mytype = New mytype; list.AddLast(m2)
Local m3:mytype = New mytype; list.AddLast(m3)
Local m4:mytype = New mytype; list.AddLast(m4)
Local m5:mytype = New mytype; list.AddLast(m5)
Local m6:mytype = Null
Local mlink:TLink 

mlink = list.FindLink(m2)
If mlink Notify mytype(mlink.Value()).id
	
mlink = list.FindLink(m6)
If mlink Notify mytype(mlink.Value()).id


Example of using ValueAtIndex
Local list:Tlist = CreateList()

Type mytype
	Field id
	Method New()
		id = Rand(0,255)
	End Method
End Type

Local m1:mytype = New mytype; list.AddLast(m1)
Local m2:mytype = New mytype; list.AddLast(m2)
Local m3:mytype = New mytype; list.AddLast(m3)
Local m4:mytype = New mytype; list.AddLast(m4)
Local m5:mytype = New mytype; list.AddLast(m5)
Local m:mytype

m = mytype(list.ValueAtIndex(0))
If m Notify m.id
	
m = mytype(list.ValueAtIndex(3))
If m Notify m.id


Example of using Compare
Local list:Tlist = CreateList()

Type mytype
	Field id
	Method New()
		id = Rand(0,255)
	End Method
	
	Method Compare(other:Object)
		Return id-mytype(other).id
	End Method
End Type

Local m1:mytype = New mytype; list.AddLast(m1)
Local m2:mytype = New mytype; list.AddLast(m2)
Local m3:mytype = New mytype; list.AddLast(m3)
Local m4:mytype = New mytype; list.AddLast(m4)
Local m5:mytype = New mytype; list.AddLast(m5)
Local m:mytype

list.Sort()
For m = EachIn list
	Notify m.id
Next



JoJo(Posted 2005) [#3]
Thanks! But how do you find an object from this code?

Local list:Tlist = CreateList()

Type mytype
	Field id
	Method New()
		id = Rand(0,255)
	End Method
End Type

for local i:int = 0 to 4
   Local m1:mytype = New mytype; list.AddLast(m1)
next